Class: SpeedLightning::Client
- Inherits:
-
Object
- Object
- SpeedLightning::Client
- Includes:
- HTTParty, CheckoutLinkMethods
- Defined in:
- lib/speed_lightning/client.rb
Constant Summary collapse
- API_URL =
"https://api.tryspeed.com/"
Instance Attribute Summary collapse
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
Instance Method Summary collapse
-
#initialize(secret_key:) ⇒ Client
constructor
A new instance of Client.
- #make_request(endpoint, request_type, body_hash = nil) ⇒ Object
Methods included from CheckoutLinkMethods
#create_checkout_link, #retrieve_checkout_link
Methods included from Retryable
Constructor Details
#initialize(secret_key:) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/speed_lightning/client.rb', line 12 def initialize(secret_key:) @secret_key = secret_key end |
Instance Attribute Details
#api_secret ⇒ Object
Returns the value of attribute api_secret.
9 10 11 |
# File 'lib/speed_lightning/client.rb', line 9 def api_secret @api_secret end |
Instance Method Details
#make_request(endpoint, request_type, body_hash = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/speed_lightning/client.rb', line 16 def make_request(endpoint, request_type, body_hash = nil) headers = { "Accept" => "application/json", "Speed-Version" => "2022-04-15", "Authorization" => "Basic " + Base64.strict_encode64(@secret_key + ":") } headers["Content-Type"] = "application/json" if body_hash = { headers: headers } [:body] = body_hash.to_json if body_hash full_url = API_URL + endpoint response = case request_type when :get self.class.get(full_url, ) when :post self.class.post(full_url, ) end parsed_response = JSON.parse(response.body) if parsed_response['errors'] && !parsed_response['errors'].empty? = parsed_response['errors'].map { |error| error['message'] }.compact = .join(', ') raise SpeedLightning::Error, end parsed_response end |