Class: Yhd::Client
Overview
API Client
Constant Summary collapse
- DEFAULT_ENDPOINT =
"http://openapi.yhd.com"
- DEFAULT_PATH =
"/app/api/rest/router"
Instance Attribute Summary collapse
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
-
#app_secret ⇒ Object
readonly
Returns the value of attribute app_secret.
-
#session_key ⇒ Object
readonly
Returns the value of attribute session_key.
Instance Method Summary collapse
-
#connection_options ⇒ Hash
Connection options for faraday.
-
#delete(params = {}) ⇒ Object
Perform an HTTP DELETE request.
- #endpoint ⇒ String
-
#get(params = {}) ⇒ Object
Perform an HTTP GET request.
-
#initialize(options) ⇒ Client
constructor
Initializes a new Client object.
- #middleware ⇒ Faraday::RackBuilder
-
#post(params = {}) ⇒ Object
Perform an HTTP POST request.
-
#put(params = {}) ⇒ Object
Perform an HTTP PUT request.
- #user_agent ⇒ String
Methods included from Orders
#get_detail_orders, #get_orders
Constructor Details
#initialize(options) ⇒ Client
Initializes a new Client object
22 23 24 25 26 27 |
# File 'lib/yhd/client.rb', line 22 def initialize() @app_key = .fetch(:app_key) @app_secret = .fetch(:app_secret) @session_key = .fetch(:session_key) @endpoint = [:endpoint] end |
Instance Attribute Details
#app_key ⇒ Object (readonly)
Returns the value of attribute app_key.
14 15 16 |
# File 'lib/yhd/client.rb', line 14 def app_key @app_key end |
#app_secret ⇒ Object (readonly)
Returns the value of attribute app_secret.
14 15 16 |
# File 'lib/yhd/client.rb', line 14 def app_secret @app_secret end |
#session_key ⇒ Object (readonly)
Returns the value of attribute session_key.
14 15 16 |
# File 'lib/yhd/client.rb', line 14 def session_key @session_key end |
Instance Method Details
#connection_options ⇒ Hash
Connection options for faraday
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yhd/client.rb', line 42 def { :builder => middleware, :headers => { :accept => 'application/json', :user_agent => user_agent, }, :request => { :open_timeout => 10, :timeout => 30, } } end |
#delete(params = {}) ⇒ Object
Perform an HTTP DELETE request
86 87 88 |
# File 'lib/yhd/client.rb', line 86 def delete(params = {}) request(:delete, params) end |
#endpoint ⇒ String
30 31 32 |
# File 'lib/yhd/client.rb', line 30 def endpoint @endpoint ||= DEFAULT_ENDPOINT end |
#get(params = {}) ⇒ Object
Perform an HTTP GET request
71 72 73 |
# File 'lib/yhd/client.rb', line 71 def get(params = {}) request(:get, params) end |
#middleware ⇒ Faraday::RackBuilder
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yhd/client.rb', line 57 def middleware Faraday::RackBuilder.new do |faraday| # Checks for files in the payload, otherwise leaves everything untouched faraday.request :multipart # Encodes as "application/x-www-form-urlencoded" if not already encoded faraday.request :url_encoded # Parse JSON response bodies faraday.response :parse_json # Set default HTTP adapter faraday.adapter :net_http end end |
#post(params = {}) ⇒ Object
Perform an HTTP POST request
76 77 78 |
# File 'lib/yhd/client.rb', line 76 def post(params = {}) request(:post, params) end |
#put(params = {}) ⇒ Object
Perform an HTTP PUT request
81 82 83 |
# File 'lib/yhd/client.rb', line 81 def put(params = {}) request(:put, params) end |