Class: Yotpo::Client

Inherits:
Object
  • Object
show all
Includes:
Account, AccountPlatform, Product, Purchase, Reminder, Review, User
Defined in:
lib/yotpo/client.rb

Instance Method Summary collapse

Methods included from Purchase

#create_new_purchase, #create_new_purchases, #get_purchases

Methods included from User

#create_user, #get_login_url, #get_oauth_token

Methods included from Review

#create_review, #get_product_reviews

Methods included from Reminder

#send_test_reminder

Methods included from Product

#get_all_bottom_lines, #get_product_bottom_line

Methods included from AccountPlatform

#create_account_platform

Methods included from Account

#check_minisite_subdomain, #update_account

Constructor Details

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

Creates a new instance of Yotpo::Client

Parameters:

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

    The url to yotpo api (api.yotpo.com)

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

    The maximum parallel request to do (5)



33
34
35
36
# File 'lib/yotpo/client.rb', line 33

def initialize(url = 'https://api.yotpo.com', parallel_requests = 5)
  @url = url
  @parallel_requests = parallel_requests
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 Yotpo API



78
79
80
81
82
# File 'lib/yotpo/client.rb', line 78

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 Yotpo API

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

    the url params that should be passed in the request



43
44
45
46
47
48
# File 'lib/yotpo/client.rb', line 43

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

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


92
93
94
95
96
# File 'lib/yotpo/client.rb', line 92

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 Yotpo API

  • params (Hash)

    the body of the request



55
56
57
58
59
60
# File 'lib/yotpo/client.rb', line 55

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 Yotpo API

  • params (Hash)

    the body of the request



67
68
69
70
71
72
# File 'lib/yotpo/client.rb', line 67

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