Class: Shoppy::Client

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

Class Method Summary collapse

Class Method Details

.auth(hostname, license) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/shoppy/client.rb', line 15

def self.auth(hostname, license)
  begin
    response = self.get('validate', {:domain => hostname, :license => license})
    return response.parsed_response
  rescue => e
    return 'error' => e.message
  end
end

.delete(path, params = nil) ⇒ Object



36
37
38
# File 'lib/shoppy/client.rb', line 36

def self.delete(path, params = nil)
  self.execute(:delete, path, params)
end

.execute(method, path, params = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shoppy/client.rb', line 40

def self.execute(method, path, params = nil)
  begin
    request = HTTMultiParty.send(method, Shoppy.api_url(path), { query: params, timeout: 300 })
    if request.respond_to?('parsed_response')
      return request.parsed_response
    else
      return request
    end
  rescue => e
    return 'error' => e.message # error
  end
end

.get(path, params = nil) ⇒ Object



24
25
26
# File 'lib/shoppy/client.rb', line 24

def self.get(path, params = nil)
  self.execute(:get, path, params)
end

.post(path, params) ⇒ Object



28
29
30
# File 'lib/shoppy/client.rb', line 28

def self.post(path, params)
  self.execute(:post, path, params)
end

.put(path, params) ⇒ Object



32
33
34
# File 'lib/shoppy/client.rb', line 32

def self.put(path, params)
 self.execute(:put, path, params)
end