Module: Helpshift
- Includes:
- HTTParty
- Defined in:
- lib/helpshift.rb,
lib/helpshift/version.rb
Defined Under Namespace
Classes: CONFIGURATION
Constant Summary collapse
- BASE_DOMAIN =
'https://api.helpshift.com/v1/'.freeze
- ConfigurationError =
Class.new(StandardError)
- VERSION =
'0.1.2'.freeze
Class Method Summary collapse
- .base_uri ⇒ Object
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
- .get(path, query = {}) ⇒ Object
- .headers ⇒ Object
- .post(path, body) ⇒ Object
- .put(path, body) ⇒ Object
Class Method Details
.base_uri ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/helpshift.rb', line 19 def self.base_uri @base_uri ||= if config.customer_domain "#{BASE_DOMAIN}#{config.customer_domain}" else raise ConfigurationError, 'customer_domain is required' end end |
.config ⇒ Object
11 12 13 |
# File 'lib/helpshift.rb', line 11 def self.config @config ||= CONFIGURATION.new end |
.configure {|config| ... } ⇒ Object
15 16 17 |
# File 'lib/helpshift.rb', line 15 def self.configure yield(config) end |
.get(path, query = {}) ⇒ Object
36 37 38 |
# File 'lib/helpshift.rb', line 36 def self.get(path, query = {}) perform_request Net::HTTP::Get, path, base_uri: base_uri, query: query, headers: headers, format: :json end |
.headers ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/helpshift.rb', line 27 def self.headers @headers ||= if config.api_key require 'base64' { 'Accept' => 'application/json', 'Authorization' => "Basic #{::Base64.encode64(config.api_key).gsub("\n", '')}" } else raise ConfigurationError, 'api_key is required' end end |
.post(path, body) ⇒ Object
44 45 46 |
# File 'lib/helpshift.rb', line 44 def self.post(path, body) perform_request Net::HTTP::Post, path, base_uri: base_uri, headers: headers, body: body, format: :json end |
.put(path, body) ⇒ Object
40 41 42 |
# File 'lib/helpshift.rb', line 40 def self.put(path, body) perform_request Net::HTTP::Put, path, base_uri: base_uri, headers: headers, body: body, format: :json end |