lib/chord.rb in chord-0.0.2 vs lib/chord.rb in chord-0.0.3

- old
+ new

@@ -1,12 +1,28 @@ require 'httparty' module Chord class << self - attr_writer :env - def env; @env || :staging; end # :staging by default + attr_accessor :base_url + attr_accessor :api_key + + def config(options) + self.base_url = options[:base_url] + self.api_key = options[:api_key] + end + + def config_from_file(filepath) + if File.exist?(filepath) + require 'yaml' + config = YAML.load(File.read(filepath), symbolize_names: true) + Chord.config( + base_url: config[:base_url], + api_key: config[:api_key] + ) + end + end end class Base include HTTParty @@ -33,16 +49,16 @@ url = base_url + base_path + '?' + hash_to_query(query_options) get(url, http_options).parsed_response end def base_url - CHORD_API_CONFIG[Chord.env][:base_url] + Chord.base_url end def http_options {headers: { - 'Authorization' => "Bearer #{CHORD_API_CONFIG[Chord.env][:api_key]}", + 'Authorization' => "Bearer #{Chord.api_key}", 'Content-Type' => 'application/json' }} end private # -------------------------------------------------------------- @@ -173,9 +189,17 @@ discount_by: discount } self.class.post(base_url + "hub/orders/#{order_id}/adjustments", http_options.merge(body: attributes.to_json) ).parsed_response + end + + def subscription_installment? + channel == 'subscriptions' + end + + def subscription_start? + subscription_in_cart end end class Role < Base