Class: Winnie::Client

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

Defined Under Namespace

Classes: CommandFailedException, ResourceNotFoundException, UnauthorizedException, UnsupportedException

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



3
4
5
# File 'lib/winnie/client.rb', line 3

def initialize(api_key)
  @api_key = api_key
end

Class Method Details

.versionObject



43
44
45
# File 'lib/winnie/client.rb', line 43

def self.version
  VERSION
end

Instance Method Details

#accountObject



11
12
13
# File 'lib/winnie/client.rb', line 11

def 
  get('/api/account')
end

#appsObject



15
16
17
# File 'lib/winnie/client.rb', line 15

def apps
  get('/api/apps')
end

#command(command, code_name) ⇒ Object



19
20
21
# File 'lib/winnie/client.rb', line 19

def command(command, code_name)
  post("/api/apps/#{code_name}/command", :body => command)
end

#get(path) ⇒ Object



27
28
29
# File 'lib/winnie/client.rb', line 27

def get(path)
  request(path, :get)
end

#post(path, params = {}) ⇒ Object



23
24
25
# File 'lib/winnie/client.rb', line 23

def post(path, params = {})
  request(path, :post, params)
end

#request(path, method, params = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/winnie/client.rb', line 31

def request(path, method, params = {})
  headers = {:accept => :json, :content_type => :json}.merge(Client.winnie_headers)
  params.merge!(:api_key => @api_key)

  RestClient::Request.execute(
    :method   => method,
    :url      => "#{winnie_url}#{path}",
    :headers  => headers,
    :payload  => params.to_json
  ) { |response, request| process_response(response) }
end

#winnie_urlObject



7
8
9
# File 'lib/winnie/client.rb', line 7

def winnie_url
  ENV['WINNIE_URL'] || 'https://admin.winniecloud.com'
end