Class: Seoshop::Client

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

Constant Summary collapse

SERVER_EU1_LIVE =
'https://api.webshopapp.com/'
SERVER_US1_LIVE =
'https://api.shoplightspeed.com/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Brand

#get_brand

Methods included from Account

#get_rate_limit

Methods included from Customer

#get_customer, #get_customers, #get_customers_count

Methods included from ProductCategory

#get_categories_count, #get_category, #get_product_category_path

Methods included from Product

#get_product, #get_products, #get_products_count

Methods included from ShopTracking

#delete_tracking, #get_tracking, #get_trackings, #get_trackings_count, #post_tracking, #update_tracking

Methods included from ShopScript

#delete_script, #get_script, #get_scripts, #get_scripts_count, #post_script, #update_script

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(api_key, api_secret, access_token, shop_language, cluster_id = 'eu1', parallel_requests = 5) ⇒ Client

Creates a new instance of Seoshop::Client

Parameters:

  • api_key (String)

    The App api key

  • api_secret (String)

    The App secret

  • access_token (String)

    The shop access token

  • shop_language (String)

    The shop language

  • cluster_id (String) (defaults to: 'eu1')

    The shop cluster id

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

    The maximum parallel request to do (5)



48
49
50
51
52
53
54
55
# File 'lib/seoshop-api/client.rb', line 48

def initialize(api_key, api_secret, access_token, shop_language, cluster_id = 'eu1', parallel_requests = 5)
  @api_key = api_key
  @api_secret = api_secret
  @access_token = access_token
  @shop_language = shop_language
  @url = get_url(cluster_id)
  @parallel_requests = parallel_requests
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



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

def api_secret
  @api_secret
end

#shop_languageObject

Returns the value of attribute shop_language.



34
35
36
# File 'lib/seoshop-api/client.rb', line 34

def shop_language
  @shop_language
end

Instance Method Details

#delete(url) ⇒ Object

Does a DELETE request to the url with the params

Parameters:

  • url (String)

    the relative path in the Seoshop API



108
109
110
111
112
# File 'lib/seoshop-api/client.rb', line 108

def delete(url)
  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



73
74
75
76
77
78
# File 'lib/seoshop-api/client.rb', line 73

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

#get_url(cluster_id) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/seoshop-api/client.rb', line 57

def get_url(cluster_id)
  case cluster_id
    when 'eu1'
      SERVER_EU1_LIVE
    when 'us1'
      SERVER_US1_LIVE
    else
      SERVER_EU1_LIVE
  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


122
123
124
125
126
# File 'lib/seoshop-api/client.rb', line 122

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



85
86
87
88
89
90
# File 'lib/seoshop-api/client.rb', line 85

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



97
98
99
100
101
102
# File 'lib/seoshop-api/client.rb', line 97

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