Class: Storenvy::Client
- Inherits:
-
Object
- Object
- Storenvy::Client
- Defined in:
- lib/storenvy/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#delete(url, params) ⇒ Object
Does a DELETE request to the url with the params.
-
#get(url, params = {}) ⇒ Object
Does a GET request to the url with the params.
-
#in_parallel ⇒ Object
Does a parallel request to the api for all of the requests in the block.
-
#initialize(url = 'https://api.storenvy.com', parallel_requests = 5) ⇒ Client
constructor
Creates a new instance of Storenvy::Client.
-
#post(url, params) ⇒ Object
Does a POST request to the url with the params.
-
#put(url, params) ⇒ Object
Does a PUT request to the url with the params.
Methods included from Product
#create_product, #delete_product, #get_product, #get_products, #update_product
Methods included from User
Methods included from Template
#get_templates, #update_template
Methods included from Store
Methods included from Order
Constructor Details
#initialize(url = 'https://api.storenvy.com', parallel_requests = 5) ⇒ Client
Creates a new instance of Storenvy::Client
30 31 32 33 |
# File 'lib/storenvy/client.rb', line 30 def initialize(url = 'https://api.storenvy.com', parallel_requests = 5) @url = url @parallel_requests = parallel_requests end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
23 24 25 |
# File 'lib/storenvy/client.rb', line 23 def access_token @access_token end |
Instance Method Details
#delete(url, params) ⇒ Object
Does a DELETE request to the url with the params
78 79 80 81 82 83 84 |
# File 'lib/storenvy/client.rb', line 78 def delete(url, params) params = convert_hash_keys(params) params[:access_token] = @access_token if @access_token preform(url, :delete) do return connection.delete(url) end end |
#get(url, params = {}) ⇒ Object
Does a GET request to the url with the params
40 41 42 43 44 45 46 |
# File 'lib/storenvy/client.rb', line 40 def get(url, params = {}) params = params.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo} params[:access_token] = @access_token if @access_token preform(url, :get, params: params) do return connection.get(url, params) end end |
#in_parallel ⇒ Object
Does a parallel request to the api for all of the requests in the block
94 95 96 97 98 |
# File 'lib/storenvy/client.rb', line 94 def in_parallel connection.in_parallel do yield end end |
#post(url, params) ⇒ Object
Does a POST request to the url with the params
53 54 55 56 57 58 59 |
# File 'lib/storenvy/client.rb', line 53 def post(url, params) params = convert_hash_keys(params) params[:access_token] = @access_token if @access_token preform(url, :post, params: params) do return connection.post(url, params) end end |
#put(url, params) ⇒ Object
Does a PUT request to the url with the params
66 67 68 69 70 71 72 |
# File 'lib/storenvy/client.rb', line 66 def put(url, params) params = convert_hash_keys(params) params[:access_token] = @access_token if @access_token preform(url, :put, params: params) do return connection.put(url, params) end end |