Class: Zcloudjp::Client
- Inherits:
-
Object
- Object
- Zcloudjp::Client
- Includes:
- HTTParty
- Defined in:
- lib/zcloudjp/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#method_missing(method, *args, &block) ⇒ Object
Defines the method if not defined yet.
- #request_options ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 |
# File 'lib/zcloudjp/client.rb', line 13 def initialize(={}) @api_key = .delete(:api_key) || ENV['ZCLOUDJP_API_KEY'] @base_uri = [:endpoint] || "https://my.z-cloud.jp" unless @api_key; raise ArgumentError, "options[:api_key] required"; end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Defines the method if not defined yet.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zcloudjp/client.rb', line 33 def method_missing(method, *args, &block) self.class.class_eval do attr_accessor method.to_sym # Defined a method according to the given method name define_method method.to_sym do obj = OpenStruct.new(request_options: ) obj.extend Zcloudjp.const_get(method.capitalize.to_sym) instance_variable_set(:"@#{method}", obj) end end # Sends to the now-defined method. self.__send__(method.to_sym) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/zcloudjp/client.rb', line 11 def api_key @api_key end |
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
11 12 13 |
# File 'lib/zcloudjp/client.rb', line 11 def base_uri @base_uri end |
Instance Method Details
#request_options ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/zcloudjp/client.rb', line 20 def = { :base_uri => @base_uri, :headers => { "X-API-KEY" => @api_key, "Content-Type" => "application/json; charset=utf-8", "Accept" => "application/json", "User-Agent" => Zcloudjp::USER_AGENT } } end |