Class: Sqwiggle::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sqwiggle/api/client.rb

Defined Under Namespace

Classes: NoTokenError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#tokenObject

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

#inspectObject



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