Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App key #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ end
```
That is it you are ready

Now lets make some public calls to our api. Public calls only require you to use a valid app_key.
Now lets make some public calls to our api. Public calls only require you to use a valid app_key.

NOTE: If you've configured Yotpo as demonstrated above, the app_key param becomes
optional for all requests. If you want to pass in a different app_key or be
explicit, providing it in the args will take precedence over the configuration.
Upcoming examples include app_key to demonstrate that it is required for a
request to be valid.

Creating your first review using the API

Expand Down
4 changes: 2 additions & 2 deletions lib/yotpo/api/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def update_account(params)
},
utoken: params[:utoken]
}
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
put("/apps/#{app_key}", request)
end

Expand All @@ -35,7 +35,7 @@ def update_account(params)
# @option params [String] :app_key the account app key that was created at registration
# @option params [String] :subdomain the subdomain to check
def check_minisite_subdomain(params)
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
subdomain = params[:subdomain]
utoken = params[:utoken]
get("/apps/#{app_key}/subomain_check/#{subdomain}?utoken=#{utoken}")
Expand Down
2 changes: 1 addition & 1 deletion lib/yotpo/api/account_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create_account_platform(params)
},
utoken: params[:utoken]
}
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
post("/apps/#{app_key}/account_platform", request)
end
end
Expand Down
8 changes: 6 additions & 2 deletions lib/yotpo/api/account_social.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def create_account_social(params)
},
utoken: params[:utoken]
}
app_key = params[:app_key] || Yotpo.app_key
post("/apps/#{params[:app_key]}/account_socials", request)
end

Expand All @@ -23,14 +24,17 @@ def update_account_social(params)
utoken: params.delete(:utoken)
}
request[:account_social] = params
put("/apps/#{params.delete(:app_key)}/account_socials/#{params.delete(:id)}", request)
app_key = params[:app_key] || Yotpo.app_key
params.delete(:app_key)
put("/apps/#{app_key}/account_socials/#{params.delete(:id)}", request)
end

def get_account_social(params)
request = {
utoken: params[:utoken]
}
get("/apps/#{params[:app_key]}/account_socials", request)
app_key = params[:app_key] || Yotpo.app_key
get("/apps/#{app_key}/account_socials", request)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/yotpo/api/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def update_comment_avatar(params)
comments_avatar_data: params[:comments_avatar_data],
comments_display_name: params[:comments_display_name]
}
put("/apps/#{params[:app_key]}/app_comment_avatar", request)
app_key = params[:app_key] || Yotpo.app_key
put("/apps/#{app_key}/app_comment_avatar", request)
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/yotpo/api/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Oauth
def validate_token(params)
request = {
token: params[:utoken],
app_key: params[:app_key]
app_key: params[:app_key] || Yotpo.app_key
}
get('/oauth/validate_token', request)
end
Expand Down
6 changes: 4 additions & 2 deletions lib/yotpo/api/owner_feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ def user_enable_feature(params)
user_enabled: params[:user_enabled]
}
}
put("apps/#{params[:app_key]}/features/#{params[:feature_id]}", request)
app_key = params[:app_key] || Yotpo.app_key
put("apps/#{app_key}/features/#{params[:feature_id]}", request)
end

def get_owner_features(params)
request = {
utoken: params[:utoken]
}
get("apps/#{params[:app_key]}/features", request)
app_key = params[:app_key] || Yotpo.app_key
get("apps/#{app_key}/features", request)
end

private
Expand Down
6 changes: 4 additions & 2 deletions lib/yotpo/api/owner_feature_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def owner_feature_settings(params)
request = {
utoken: params[:utoken],
}
get("apps/#{params[:app_key]}/features/#{params[:feature_id]}/feature_settings", request)
app_key = params[:app_key] || Yotpo.app_key
get("apps/#{app_key}/features/#{params[:feature_id]}/feature_settings", request)
end

def update_feature_settings(params)
Expand All @@ -29,7 +30,8 @@ def update_feature_settings(params)
value: params[:value],
key: params[:key]
}
put("apps/#{params[:app_key]}/features/#{params[:feature_id]}/feature_settings/#{params[:feature_settings_id]}", request)
app_key = params[:app_key] || Yotpo.app_key
put("apps/#{app_key}/features/#{params[:feature_id]}/feature_settings/#{params[:feature_settings_id]}", request)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/yotpo/api/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_all_bottom_lines(params)
since_id: params[:since_id]
}
request.delete_if{|key,val| val.nil?}
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
get("/apps/#{app_key}/bottom_lines", request)
end

Expand All @@ -17,13 +17,13 @@ def get_all_bottom_lines(params)
# @option params [String] :app_key the accounts app key that was given to it upon registration
# @option params [String] :product_id the id of the product
def get_product_bottom_line(params)
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
sku = params[:product_id]
get("/products/#{app_key}/#{sku}/bottomline")
end

def get_product_url(params)
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
product_id = params[:product_id]
request = {
utoken: params[:utoken],
Expand All @@ -35,4 +35,4 @@ def get_product_url(params)
get("/products/#{app_key}/product_url", request)
end
end
end
end
8 changes: 4 additions & 4 deletions lib/yotpo/api/purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create_new_purchase(params)
platform: params[:platform],
products: params[:products]
}
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
post("/apps/#{app_key}/purchases", request)
end

Expand All @@ -21,7 +21,7 @@ def create_new_purchases(params)
platform: params[:platform],
orders: params[:orders]
}
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
post("/apps/#{app_key}/purchases/mass_create", request)
end

Expand All @@ -34,8 +34,8 @@ def get_purchases(params)
count: params[:count] || 10
}
request.delete_if{|key, value| value.nil? }
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
get("/apps/#{app_key}/purchases", request)
end
end
end
end
5 changes: 3 additions & 2 deletions lib/yotpo/api/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module Yotpo
module Question

def question_send_confirmation(params)
app_key = params[:app_key] || Yotpo.app_key
request = {
appkey: params[:app_key],
appkey: app_key,
sku: params[:product_id],
product_title: params[:product_title],
product_url: params[:product_url],
Expand Down Expand Up @@ -41,4 +42,4 @@ def question_create_by_token(params)
end

end
end
end
2 changes: 1 addition & 1 deletion lib/yotpo/api/reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def send_test_reminder(params)
utoken: params[:utoken],
email: params[:email]
}
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
post("/apps/#{app_key}/reminders/send_test_email", request)
end
end
Expand Down
9 changes: 5 additions & 4 deletions lib/yotpo/api/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ module Review
# @option params [String] :utoken the token of the user who wrote the review (if one exists)
# @return [::Hashie::Mash] The new review with all of it's date
def create_review(params)
app_key = params[:app_key] || Yotpo.app_key
request = {
appkey: params[:app_key],
appkey: app_key,
sku: params[:product_id],
domain: params[:shop_domain],
product_title: params[:product_title],
Expand Down Expand Up @@ -55,7 +56,7 @@ def create_review(params)
# @option params [Boolean] :deleted Include deleted reviews

def get_all_reviews(params)
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
sku = params[:product_id]
request = {
utoken: params[:utoken],
Expand Down Expand Up @@ -84,7 +85,7 @@ def get_all_reviews(params)
# @option params [String] :since_date the date from which to start retrieving reviews
# @option params [String] :utoken the users utoken to get the reviews that are most relevant to that user
def get_product_reviews(params)
app_key = params[:app_key]
app_key = params[:app_key] || Yotpo.app_key
sku = params[:product_id]
request = {
page: params[:page] || 1,
Expand All @@ -101,4 +102,4 @@ def add_vote_to_review(params)
get("reviews/#{params[:review_id]}/vote/#{params[:vote_value]}")
end
end
end
end
8 changes: 5 additions & 3 deletions lib/yotpo/api/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def create_user(params)
# @option params [String] :secret app secret received at the registration
# @return [Hash] that includes access_token and the token_type
def get_oauth_token(params)
app_key = params[:app_key] || Yotpo.app_key
request = {
client_id: params[:app_key],
client_id: app_key,
client_secret: params[:secret],
grant_type: 'client_credentials'
}
Expand All @@ -54,8 +55,9 @@ def get_oauth_token(params)
# @option params [String] :app_key that was received when registered to www.yotpo.com
# @option params [String] :secret that was received when registered to www.yotpo.com
def get_login_url(params)
app_key = params[:app_key] || Yotpo.app_key
request = {
app_key: params[:app_key],
app_key: app_key,
secret: params[:secret]
}
get('/users/b2blogin.json', request)
Expand All @@ -66,4 +68,4 @@ def anonymous_user_confirmation(params)
end

end
end
end
2 changes: 1 addition & 1 deletion lib/yotpo/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ def convert_hash_keys(value)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/yotpo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Yotpo
VERSION = '1.0.1'
VERSION = '1.0.2'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the version change in a separate commit / PR.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did Yotpo not use this PR? Coming to this gem now, and it seems crazy to provide a known key on each and every call.

end