lib/shipcloud.rb in shipcloud-0.2.0 vs lib/shipcloud.rb in shipcloud-0.3.0

- old
+ new

@@ -2,27 +2,28 @@ require "net/https" require "json" require "shipcloud/version" module Shipcloud - API_BASE = "api.shipcloud.io" API_VERSION = "v1" ROOT_PATH = File.dirname(__FILE__) API_HEADERS = { "Content-Type" => "application/json", - "User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API v#{Shipcloud::API_VERSION}, #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}" + "User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}" } @@api_key = nil autoload :Base, "shipcloud/base" autoload :Shipment, "shipcloud/shipment" module Operations autoload :Create, "shipcloud/operations/create" autoload :Find, "shipcloud/operations/find" + autoload :Delete, "shipcloud/operations/delete" + autoload :Update, "shipcloud/operations/update" end module Request autoload :Base, "shipcloud/request/base" autoload :Connection, "shipcloud/request/connection" @@ -32,21 +33,45 @@ class ShipcloudError < StandardError; end class AuthenticationError < ShipcloudError; end class APIError < ShipcloudError; end + class << self + attr_accessor :configuration + end + + def self.configuration + @configuration ||= Configuration.new + end + + def self.configure + yield(configuration) + end + + + class Configuration + attr_accessor :api_key, :api_base, :use_ssl + + def initialize + @api_key = nil + @api_base = 'api.shipcloud.io' + @use_ssl = true + end + end + # Returns the set api key # # @return [String] The api key def self.api_key - @@api_key + configuration.api_key end # Sets the api key # # @param [String] api_key The api key def self.api_key=(api_key) @@api_key = api_key + configuration.api_key = api_key end # Makes a request against the shipcloud API # # @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete