Class: Yotpo::Client

Inherits:
Object
  • Object
show all
Includes:
Account, AccountPlatform, AccountSocial, Answer, Comment, Feature, Image, Oauth, OwnerFeature, OwnerFeatureSetting, Product, Purchase, Question, 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 Answer

#add_shop_owner_answer

Methods included from Question

#question_create_by_token, #question_send_confirmation

Methods included from User

#anonymous_user_confirmation, #create_user, #get_login_url, #get_oauth_token

Methods included from Review

#add_vote_to_review, #create_review, #get_all_reviews, #get_product_reviews, #get_review

Methods included from Reminder

#send_test_reminder

Methods included from Product

#get_all_bottom_lines, #get_product_bottom_line, #get_product_url, #get_products_information

Methods included from OwnerFeatureSetting

#get_feature_settings, #mass_update_feature_settings, #owner_feature_settings, #update_feature_settings

Methods included from OwnerFeature

#add_feature, #get_owner_features, #remove_feature, #user_enable_feature

Methods included from Oauth

#validate_token

Methods included from Image

#get_image, #list_images

Methods included from Feature

#get_features

Methods included from Comment

#create_comment, #update_comment, #update_comment_avatar

Methods included from AccountSocial

#create_account_social, #get_account_social, #update_account_social

Methods included from AccountPlatform

#create_account_platform

Methods included from Account

#check_lock_state, #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)



50
51
52
53
# File 'lib/yotpo/client.rb', line 50

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



95
96
97
98
99
100
# File 'lib/yotpo/client.rb', line 95

def delete(url, params)
  params = convert_hash_keys(params)
  preform(url, :delete, params: params) do
    return connection.delete(url, params)
  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



60
61
62
63
64
65
# File 'lib/yotpo/client.rb', line 60

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


110
111
112
113
114
# File 'lib/yotpo/client.rb', line 110

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



72
73
74
75
76
77
# File 'lib/yotpo/client.rb', line 72

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



84
85
86
87
88
89
# File 'lib/yotpo/client.rb', line 84

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