Skip to content

Instantly share code, notes, and snippets.

@livelikeabel
Last active April 25, 2018 12:51
Show Gist options
  • Select an option

  • Save livelikeabel/d076e546382aba00156e7f4b98af1389 to your computer and use it in GitHub Desktop.

Select an option

Save livelikeabel/d076e546382aba00156e7f4b98af1389 to your computer and use it in GitHub Desktop.
solutionOfKurlyAPI

setDeliveryGoodMorningAvailability 함수가 새벽 배송 가능 여부를 알려주는듯!

  1. setDeliveryGoodMorningAvailability 함수의 parameter인 addresses

    Address [ { jibunAddress: '서울 성동구 하왕십리동 서울도보관광코스 2코스(청계천)', roadNameAddress: '', available: false, latitude: 37.570047657863334, longitud: 127.02867018528204, area: undefined // 으잉??? state: 'Not In DB', //저녁인듯 lunchState: 'Not In DB', goodMorningAvailable: false // 기본값이 false인가? //lunchAvailable은 아예 없는건가? 언제 생기지? } ... ] // 하왕십리 했을 때, 15item 반환됨

    배열의 끝에 이게 나옴.. ::1 - - [25/Apr/2018:10:41:05 +0000] "GET /?query=%ED%95%98%EC%99%95%EC%8B%AD%EB%A6%AC HTTP/1.1" 200 4754 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"

    컬리를 통과하고 나면, area는 kurly, goodMorningAvailable은 true가 되는것 같다.

  2. addresses를 map 돌면서, address객체의 jibunAddress (address.jibunAddress)를 form에다가 더하여 준다.

2-1. body에 form 실어서 kurly api에 post로 보낼 FormData

FormData
{
  _overheadLength: 106,
  _valueLength: 57,
  _valuesToMeasure: [],
  writable: false,
  readable: true,
  dataSize: 0,
  maxDataSize: 2097152,
  pauseStreams: true,
  _released: false,
  _streams: [ 
    			'----------------------------480378260201964030663274\r\n
             	Content-Disposition: form-data; 
             	name="address"\r\n\r\n',
			 	'서울 성동구 하왕십리동 1066 텐즈힐1아파트', // form에 address객체의 jibunAddress만 넘긴다.(만약 jibunAddress가 없다면?)
			 	[Function: bound ]
  			],
  _currentStream: null,
  _boundary: '--------------------------480378260201964030663274'
}

3 마켓컬리의 api에 method는 post로, body에는 form을 넣어 request를 날리고 response를 받는다.

kurly의 response // 이걸 구현해야 한다. 만들 api가 이걸 반환해야한다.
Body {
  url: 'http://www.kurly.com/shop/proc/ajax_address_chk.php',
  status: 200,
  statusText: 'OK',
  headers: Headers {
		      			_headers: { 
                        			  date: [Array],
                                      'content-type': [Array],
                                      'transfer-encoding': [Array],
                                      connection: [Array],
                                      'set-cookie': [Array],
                                      'cache-control': [Array],
                                      expires: [Array],
                                      'last-modified': [Array],
                                      p3p: [Array],
                                      pragma: [Array],
                                      vary: [Array],
                                      'x-powered-by': [Array],
                                      server: [Array],
                                      'cf-ray': [Array],
                                      'content-encoding': [Array]
                        			}
  					},
           ok: true,
           body: { //Gunzip
	 		       _readableState: {
                		   				objectMode: false,
                                        highWaterMark: 16384,
										buffer: [Object],
                                        length: 0,
                                        pipes: null,
                                        pipesCount: 0,
                                        flowing: null,
                                        ended: false,
                                        endEmitted: false,
                                        reading: false,
                                        sync: false,
	                                    needReadable: true,
                                        emittedReadable: false,
                                        readableListening: false,
                                        resumeScheduled: false,
                                        destroyed: false,
                                        defaultEncoding: 'utf8',
                                        awaitDrain: 0,
                                        readingMore: false,
                                        decoder: null,
                                        encoding: null
             						},
						_events: {
                              		end: [Array],
                                    prefinish: [Function: prefinish],
                                    unpipe: [Function: onunpipe],
                                    drain: [Function],
                                    error: [Function: onerror],
                                    close: [Object],
                                    finish: [Object]
                            	  },
						_eventsCount: 7,
                        _maxListeners: undefined,
                        _writableState: {
											objectMode: false,
                                            highWaterMark: 16384,
                                            finalCalled: false,
                                            needDrain: false,
                                            ending: true,
                                            ended: true,
                                            finished: false,
                                            destroyed: false,
                                            decodeStrings: true,
                                            defaultEncoding: 'utf8',
                                            length: 103,
                                            writing: true,
                                            corked: 0,
                                            sync: false,
                                            bufferProcessing: false,
                                            onwrite: [Function: bound onwrite],
                                            writecb: [Function: nop],
                                            writelen: 93,
                                            bufferedRequest: [Object],
                                            lastBufferedRequest: [Object],
                                            pendingcb: 2,
                                            prefinished: false,
                                            errorEmitted: false,
                                            bufferedRequestCount: 1,
                                            corkedRequestsFree: [Object]
                        				  },
							writable: false,
                            allowHalfOpen: true,
                            _transformState: {
                                				afterTransform: [Function: bound afterTransform],
                                                needTransform: false,
                                                transforming: true,
                                                writecb: [Function: bound onwrite],
                                                writechunk: <Buffer 1f 8b 08 00 00 00 00 00 00 03 aa 56 ca 2d 4e 57 b2 52 da fd 7b d7 86 9d 2f f6 dc d6 38 70 eb f0 1e 10 43 53 e1 e0 b7 fd ab 0e 5c d9 72 7e cb 4d 3d 25 ... >,
                                                writeencoding: 'buffer'
                            				  },
                             bytesRead: 0,
                             _opts: {},
                             _chunkSize: 16384,
							 _flushFlag: 0,
							 _finishFlushFlag: 4,
							 _scheduledFlushFlag: 0,
                             _handle: Zlib {
											 onerror: [Function: bound zlibOnError],
											 buffer: <Buffer 1f 8b 08 00 00 00 00 00 00 03 aa 56 ca 2d 4e 57 b2 52 da fd 7b d7 86 9d 2f f6 dc d6 38 70 eb f0 1e 10 43 53 e1 e0 b7 fd ab 0e 5c d9 72 7e cb 4d 3d 25 ... >,
											 callback: [Function: callback] },
											 _hadError: false,
											 _buffer: <Buffer 7b 22 6d 73 67 22 3a 22 bb fb ba b0 b9 e8 bc db 28 c0 da c3 bc b9 e8 bc db 29 20 c1 f6 bf aa c0 d4 b4 cf b4 d9 2e 22 2c 22 64 65 6c 69 50 6f 6c 69 22 ... >,
											 _offset: 0,
											 _level: -1,
											 _strategy: 0 },
                              bodyUsed: false,
                              size: 0,
                              timeout: 0,
                              _raw: [],
                              _abort: false
		           			 }
}
  1. 위의 response를 response.json() 해주면 아래의 object를 얻을 수 있다.

    {
      msg: '샛별배송(자체배송)지역입니다.',
      deliPoli: 0,
      deli_title: '샛별배송',
      state: true
    }
    

만들어 주어야 할 것.

address.jibunAddress를 받으면, 그 주소가 가능한지 아닌지 4번의 포맷으로 보내주는 api

Idea

  • setDeliveryGoodMorningAvailability 함수는 response.json()의 응답값중, state와 deliPoli만 체크하기 때문에, msg 나 deli_title에 이 API가 kurly API의 임시방편임을 notice 해주는 것은 어떨까.

어떻게 만들지....?

  1. v3에 만들어야 하나....

2-1) 폴이 준 '하루컴퍼니' 직배송 가능 지역 리스트는 시 단위로 그냥 데이터 던져놓음 => 00시 이면, 시단위로 그냥 바로 true 값 리턴 해도 될 듯 ( 어떤 예외가 있을까? ex) 서울, 서울시 등 한글자한글자의 차이)

2-2) 우편번호, 구 우편번호, 시 구 동 단위의 주소 데이터 있음


url : /V3/morning

method: post

  1. post로 받은 response의 body에 form 형식의 jibunAddress가 잘 받아지는지 확인

  2. 받은거 추출

...중간의 많은 예외상황 과 로직

2-1) jibunAddress가 cj가 배송가능한 지역과 겹치는지 확인.

return jibunAddress === cj ? true : false

end) response 형식 갖추기, 날리기


Etc..

kurly의 response

{
  msg: '샛별배송(자체배송) 지역입니다.',
  deliPoli: 0,
  deli_title: '샛별배송',
  state: true
}

// kurly의 response중 마지막 부분인듯....
::1 - - [25/Apr/2018:10:31:15 +0000] "GET /?query=%ED%95%98%EC%99%95%EC%8B%AD%EB%A6%AC HTTP/1.1" 200 4754 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"

이 친구들은 뭐징?

::1 - - [25/Apr/2018:10:04:37 +0000] "GET /?query=%ED%95%98%EC%99%95%EC%8B%AD%EB%A6%AC HTTP/1.1" 200 4754 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"

-----------------------964141684448788190125089\r\n
Content-Disposition: form-data; 
name="address"\r\n\r\n',
'서울 성동구 하왕십리동 822-2 왕십리뉴타운센트라스아파트',
[Function: bound ] ],
_currentStream: null,
_boundary: '

애도 뭘까?

::1 - - [25/Apr/2018:10:00:33 +0000] "GET /?query=%ED%95%98%EC%99%95%EC%8B%AD%EB%A6%AC HTTP/1.1" 200 4754 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment