Class: Seoshop::Client

Inherits:
Object
  • Object
show all
Includes:
Account, Customer, Order, Product, Shop
Defined in:
lib/seoshop-api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Account

#get_rate_limit

Methods included from Customer

#get_customer, #get_customers, #get_customers_count

Methods included from Product

#get_product, #get_products, #get_products_count

Methods included from Shop

#get_shop, #get_shop_company, #get_shop_website

Methods included from Order

#get_order, #get_order_products, #get_orders, #get_orders_count

Constructor Details

#initialize(access_token, shop_language, url = 'https://api.webshopapp.com', parallel_requests = 5) ⇒ Client

Creates a new instance of Seoshop::Client

Parameters:

  • url (String) (defaults to: 'https://api.webshopapp.com')

    The url to Seoshop api (api.webshopapp.com)

  • parallel_requests (Integer String) (defaults to: 5)

    The maximum parallel request to do (5)



30
31
32
33
34
35
# File 'lib/seoshop-api/client.rb', line 30

def initialize(access_token, shop_language, url = 'https://api.webshopapp.com', parallel_requests = 5)
  @access_token = access_token
  @shop_language = shop_language
  @url = url
  @parallel_requests = parallel_requests
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



22
23
24
# File 'lib/seoshop-api/client.rb', line 22

def access_token
  @access_token
end

#shop_languageObject

Returns the value of attribute shop_language.



23
24
25
# File 'lib/seoshop-api/client.rb', line 23

def shop_language
  @shop_language
end

Instance Method Details

#delete(url, params) ⇒ Object

Does a DELETE request to the url with the params

Parameters:

  • url (String)

    the relative path in the Seoshop API



77
78
79
80
81
# File 'lib/seoshop-api/client.rb', line 77

def delete(url, params)
  preform(url, :delete) do
    return connection.delete(url)
  end
end

#get(url, params = {}) ⇒ Object

Does a GET request to the url with the params

Parameters:

  • url (String)

    the relative path in the Seoshop API

  • params (Hash) (defaults to: {})

    the url params that should be passed in the request



42
43
44
45
46
47
# File 'lib/seoshop-api/client.rb', line 42

def get(url, params = {})
  params = params.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
  preform(url, :get, params: params) do
    return connection.get(url, params)
  end
end

#in_parallelObject

Does a parallel request to the api for all of the requests in the block

Examples:

block

Seoshop.in_parallel do
  Seoshop.create_review(review_params)
  Seoshop.()
end


91
92
93
94
95
# File 'lib/seoshop-api/client.rb', line 91

def in_parallel
  connection.in_parallel do
    yield
  end
end

#post(url, params) ⇒ Object

Does a POST request to the url with the params

Parameters:

  • url (String)

    the relative path in the Seoshop API

  • params (Hash)

    the body of the request



54
55
56
57
58
59
# File 'lib/seoshop-api/client.rb', line 54

def post(url, params)
  params = convert_hash_keys(params)
  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

Parameters:

  • url (String)

    the relative path in the Seoshop API

  • params (Hash)

    the body of the request



66
67
68
69
70
71
# File 'lib/seoshop-api/client.rb', line 66

def put(url, params)
  params = convert_hash_keys(params)
  preform(url, :put, params: params) do
    return connection.put(url, params)
  end
end