class Blinkbox::ZuulClient
Attributes
headers[RW]
Public Class Methods
new(server_uri, proxy_uri = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 10 def initialize(server_uri, proxy_uri = nil) self.class.base_uri(server_uri.to_s) self.class.http_proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) if proxy_uri self.class.debug_output($stderr) if ENV['DEBUG'] @headers = {} end
Public Instance Methods
admin_find_user(params = {}, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 121 def admin_find_user(params = {}, access_token) http_get "/admin/users", params, access_token end
admin_get_user_info(user_id, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 125 def admin_get_user_info(user_id, access_token) http_get "/admin/users/#{user_id}", {}, access_token end
authenticate(params)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 22 def authenticate(params) http_post "/oauth2/token", params end
change_password(params, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 56 def change_password(params, access_token) http_post "/password/change", params, access_token end
deregister_client(client_id, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 68 def deregister_client(client_id, access_token) http_delete "/clients/#{client_id}", {}, access_token end
extend_elevated_session(access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 42 def extend_elevated_session(access_token) http_post "/session", {}, access_token end
get_access_token_info(access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 38 def get_access_token_info(access_token) http_get "/session", {}, access_token end
get_client_info(client_id, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 26 def get_client_info(client_id, access_token) http_get "/clients/#{client_id}", {}, access_token end
get_clients_info(access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 30 def get_clients_info(access_token) http_get "/clients", {}, access_token end
get_user_info(user_id, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 34 def get_user_info(user_id, access_token) http_get "/users/#{user_id}", {}, access_token end
last_response(params = {})
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 129 def last_response(params = {}) res = HttpCapture::RESPONSES.last return nil if res.body.empty? fail "Requires format parameter" if !params[:format] case params[:format] when "json" MultiJson.load(res.body) else res end end
register_client(client, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 46 def register_client(client, access_token) params = { client_name: client.name, client_brand: client.brand, client_model: client.model, client_os: client.os } http_post "/clients", params, access_token end
register_user(user, client_options = {})
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 72 def register_user(user, client_options = {}) params = { grant_type: "urn:blinkbox:oauth:grant-type:registration", username: user.username, password: user.password, first_name: user.first_name, last_name: user.last_name, accepted_terms_and_conditions: user.accepted_terms_and_conditions, allow_marketing_communications: user.allow_marketing_communications } params.merge!(client_options) response = http_post("/oauth2/token", params) response.successful? ? MultiJson.load(response.body) : response end
register_user_with_client(user, client)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 87 def register_user_with_client(user, client) client_params = { client_name: client.name, client_brand: client.brand, client_model: client.model, client_os: client.os } register_user(user, client_params) end
reset_password(params)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 60 def reset_password(params) http_post "/password/reset", params end
revoke(refresh_token, access_token = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 97 def revoke(refresh_token, access_token = nil) http_post "/tokens/revoke", { refresh_token: refresh_token }, access_token end
update_client(client, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 101 def update_client(client, access_token) params = {} params[:client_name] = client.name if client.name_changed? params[:client_brand] = client.brand if client.brand_changed? params[:client_model] = client.model if client.model_changed? params[:client_os] = client.os if client.os_changed? http_patch "/clients/#{client.local_id}", params, access_token end
update_user(user, access_token)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 110 def update_user(user, access_token) params = {} params[:username] = user.username if user.username_changed? params[:password] = user.password if user.password_changed? params[:first_name] = user.first_name if user.first_name_changed? params[:last_name] = user.last_name if user.last_name_changed? params[:accepted_terms_and_conditions] = user.accepted_terms_and_conditions if user.accepted_terms_and_conditions_changed? params[:allow_marketing_communications] = user.allow_marketing_communications if user.allow_marketing_communications_changed? http_patch "/users/#{user.local_id}", params, access_token end
use_proxy(proxy_uri)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 17 def use_proxy(proxy_uri) proxy_uri = URI.parse(proxy_uri) if proxy_uri.is_a?(String) self.class.http_proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) end
validate_password_reset_token(params)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 64 def validate_password_reset_token(params) http_post "/password/reset/validate-token", params end
Private Instance Methods
http_call(verb, uri, params = {}, access_token = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 151 def http_call(verb, uri, params = {}, access_token = nil) headers = { "Accept" => "application/json" }.merge(@headers) headers["Authorization"] = "Bearer #{access_token}" if access_token self.class.send(verb, uri.to_s, headers: headers, query: params) HttpCapture::RESPONSES.last end
http_delete(uri, params = {}, access_token = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 147 def http_delete(uri, params = {}, access_token = nil) http_call(:delete, uri, params, access_token) end
http_get(uri, params = {}, access_token = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 143 def http_get(uri, params = {}, access_token = nil) http_call(:get, uri, params, access_token) end
http_patch(uri, body_params, access_token = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 158 def http_patch(uri, body_params, access_token = nil) http_send(:patch, uri, body_params, access_token) end
http_post(uri, body_params, access_token = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 162 def http_post(uri, body_params, access_token = nil) http_send(:post, uri, body_params, access_token) end
http_send(verb, uri, body_params, access_token = nil)
click to toggle source
# File lib/blinkbox/user/zuul_client.rb, line 166 def http_send(verb, uri, body_params, access_token = nil) headers = { "Accept" => "application/json", "Content-Type" => "application/x-www-form-urlencoded" }.merge(@headers) headers["Authorization"] = "Bearer #{access_token}" if access_token body_params.reject! { |_, v| v.nil? } body_params = URI.encode_www_form(body_params) unless body_params.is_a?(String) self.class.send(verb, uri.to_s, headers: headers, body: body_params) HttpCapture::RESPONSES.last end