Class: Hive::Client
- Inherits:
-
Object
- Object
- Hive::Client
- Includes:
- REST::API
- Defined in:
- lib/hive/connect/wix_client.rb
Instance Attribute Summary collapse
-
#api_base ⇒ Object
Returns the value of attribute api_base.
-
#api_family ⇒ Object
Returns the value of attribute api_family.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#instance_id ⇒ Object
Returns the value of attribute instance_id.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
- #user_agent ⇒ String
Class Method Summary collapse
Instance Method Summary collapse
- #headers=(options = {}) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #request(method, path, options = {}) ⇒ Object
-
#request_config=(options = {}) ⇒ Object
:nocov:.
- #wix_request(request) ⇒ Object
Methods included from REST::Redirects
Methods included from Util
#perform, #perform_with_cursor, #perform_with_object
Methods included from REST::Sites
#sites_site, #sites_site_pages
Methods included from REST::Insights
#activities_summary, #contact_activities_summary
Methods included from REST::Activities
#activities, #activity, #add_contact_activity, #contact_activities, #new_activity
Methods included from REST::Contacts
#add_contact_address, #add_contact_custom, #add_contact_email, #add_contact_note, #add_contact_phone, #add_contact_tags, #contact, #contacts, #contacts_subscribers, #contacts_tags, #new_contact, #patch_contact, #update_contact_address, #update_contact_company, #update_contact_custom, #update_contact_date, #update_contact_email, #update_contact_name, #update_contact_note, #update_contact_phone, #update_contact_picture, #upsert_contact
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hive/connect/wix_client.rb', line 21 def initialize( = {}) # Defaults @api_family = 'v1' @api_version = '1.0.0' @api_base = 'https://openapi.wix.com' .each do |key, value| send(:"#{key}=", value) end yield(self) if block_given? validate_configuration! end |
Instance Attribute Details
#api_base ⇒ Object
Returns the value of attribute api_base.
18 19 20 |
# File 'lib/hive/connect/wix_client.rb', line 18 def api_base @api_base end |
#api_family ⇒ Object
Returns the value of attribute api_family.
18 19 20 |
# File 'lib/hive/connect/wix_client.rb', line 18 def api_family @api_family end |
#api_version ⇒ Object
Returns the value of attribute api_version.
18 19 20 |
# File 'lib/hive/connect/wix_client.rb', line 18 def api_version @api_version end |
#app_id ⇒ Object
Returns the value of attribute app_id.
18 19 20 |
# File 'lib/hive/connect/wix_client.rb', line 18 def app_id @app_id end |
#instance_id ⇒ Object
Returns the value of attribute instance_id.
18 19 20 |
# File 'lib/hive/connect/wix_client.rb', line 18 def instance_id @instance_id end |
#logger ⇒ Object
Returns the value of attribute logger.
18 19 20 |
# File 'lib/hive/connect/wix_client.rb', line 18 def logger @logger end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
18 19 20 |
# File 'lib/hive/connect/wix_client.rb', line 18 def secret_key @secret_key end |
Class Method Details
.parse_instance_data(signed_instance, app_secret) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/hive/connect/wix_client.rb', line 68 def parse_instance_data(signed_instance, app_secret) signature, encoded_json = signed_instance.split('.', 2) fail Hive::SignatureError, 'invalid signed instance' if signature.nil? || encoded_json.nil? encoded_json_hack = encoded_json.length.modulo(4) == 0 ? encoded_json : encoded_json + ('=' * (4 - encoded_json.length.modulo(4))) json_str = Base64.urlsafe_decode64(encoded_json_hack) hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, app_secret, encoded_json) my_signature = Base64.urlsafe_encode64(hmac).gsub('=', '') fail Hive::SignatureError, 'the signatures do not match' if signature != my_signature Hashie::Mash.new(JSON.parse(json_str)) end |
Instance Method Details
#headers=(options = {}) ⇒ Object
35 36 37 |
# File 'lib/hive/connect/wix_client.rb', line 35 def headers=( = {}) [:headers].merge!() end |
#request(method, path, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hive/connect/wix_client.rb', line 54 def request(method, path, = {}) connection.send(method.to_sym) do |request| request.url path, .fetch(:params, {}) request.headers.update(.fetch(:headers, {})) body = .fetch(:body, {}) request.body = body if body.length > 0 end rescue Faraday::Error::TimeoutError, Timeout::Error => error raise(Hive::Response::Error::RequestTimeout, error) rescue Faraday::Error::ClientError, JSON::ParserError => error raise(Hive::Response::Error, error) end |
#request_config=(options = {}) ⇒ Object
:nocov:
40 41 42 |
# File 'lib/hive/connect/wix_client.rb', line 40 def request_config=( = {}) [:request].merge!() end |
#wix_request(request) ⇒ Object
50 51 52 |
# File 'lib/hive/connect/wix_client.rb', line 50 def wix_request(request) request(request.verb, request.path, request.) end |