Class: Campi::Client
Constant Summary collapse
- API_ARGUMENTS =
Valid arguments to build the API arguments path.
[:projects, :calendars]
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#api_arguments ⇒ Object
Use merged data to compose the API arguments path.
-
#get_accesses ⇒ Object
client = Campi::Client.new client.project(‘999999999-my-project’).get_accesses.
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #method_missing(method_name, *arguments, &block) ⇒ Object
- #respond_to?(method_name) ⇒ Boolean
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/campi/client.rb', line 12 def initialize self.class.base_uri "https://basecamp.com/#{Campi.configuration.basecamp_id}/api/v1" self.class.headers( 'User-Agent' => "#{Campi.configuration.application_name} (#{Campi.configuration.application_contact})", 'Content-Type' => 'application/json') self.class.basic_auth(Campi.configuration.username, Campi.configuration.password) @data = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/campi/client.rb', line 32 def method_missing(method_name, *arguments, &block) if API_ARGUMENTS.include?(method_name) @data.merge!({method_name => arguments[0]}) self end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/campi/client.rb', line 5 def data @data end |
Instance Method Details
#api_arguments ⇒ Object
Use merged data to compose the API arguments path.
42 43 44 45 46 47 48 |
# File 'lib/campi/client.rb', line 42 def api_arguments arguments = '' @data.each do |sym, value| arguments += "/#{sym.to_s}/#{value}" end arguments end |
#get_accesses ⇒ Object
client = Campi::Client.new client.project(‘999999999-my-project’).get_accesses
54 55 56 57 |
# File 'lib/campi/client.rb', line 54 def get_accesses path = "#{api_arguments}/accesses.json" get(path) end |
#respond_to?(method_name) ⇒ Boolean
24 25 26 |
# File 'lib/campi/client.rb', line 24 def respond_to?(method_name) API_ARGUMENTS.include?(method_name) || super end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
28 29 30 |
# File 'lib/campi/client.rb', line 28 def respond_to_missing?(method_name, include_private = false) API_ARGUMENTS.include?(method_name) || super end |