Class: Sqwiggle::Api::Client
- Inherits:
-
Object
- Object
- Sqwiggle::Api::Client
- Defined in:
- lib/sqwiggle/api/client.rb
Defined Under Namespace
Classes: NoTokenError
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
-
#url ⇒ Object
writeonly
for testing purposes.
Class Method Summary collapse
Instance Method Summary collapse
- #==(val) ⇒ Object
- #delete(endpoint) ⇒ Object
- #get(endpoint, params = {}) ⇒ Object
-
#initialize(token = nil) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #post(endpoint, params) ⇒ Object
- #put(endpoint, params) ⇒ Object
Constructor Details
#initialize(token = nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/sqwiggle/api/client.rb', line 9 def initialize(token=nil) unless @token = token || Sqwiggle.token raise NoTokenError end end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/sqwiggle/api/client.rb', line 6 def token @token end |
#url=(value) ⇒ Object
for testing purposes
7 8 9 |
# File 'lib/sqwiggle/api/client.rb', line 7 def url=(value) @url = value end |
Class Method Details
.service(key, klass) ⇒ Object
15 16 17 18 19 |
# File 'lib/sqwiggle/api/client.rb', line 15 def self.service(key, klass) define_method key, -> { instance_eval('Service').new instance_eval(klass), self } end |
Instance Method Details
#==(val) ⇒ Object
29 30 31 |
# File 'lib/sqwiggle/api/client.rb', line 29 def ==(val) self.class == val.class && val.token == token end |
#delete(endpoint) ⇒ Object
45 46 47 |
# File 'lib/sqwiggle/api/client.rb', line 45 def delete(endpoint) connection.delete endpoint end |
#get(endpoint, params = {}) ⇒ Object
33 34 35 |
# File 'lib/sqwiggle/api/client.rb', line 33 def get(endpoint, params={}) connection.get endpoint, params end |
#inspect ⇒ Object
49 50 51 52 53 |
# File 'lib/sqwiggle/api/client.rb', line 49 def inspect #This is purely to stop huge console output when inspecting resource #objects as they contain a reference to the loading client "#<Sqwiggle::Api::Client # (#{object_id})>" end |
#post(endpoint, params) ⇒ Object
41 42 43 |
# File 'lib/sqwiggle/api/client.rb', line 41 def post(endpoint, params) connection.post endpoint, params end |
#put(endpoint, params) ⇒ Object
37 38 39 |
# File 'lib/sqwiggle/api/client.rb', line 37 def put(endpoint, params) connection.put endpoint, params end |