Class: Appetize::API

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

Instance Method Summary collapse

Constructor Details

#initialize(token = nil, api_host = nil) ⇒ API

Returns a new instance of API.


7
8
9
10
11
12
# File 'lib/appetize/api.rb', line 7

def initialize(token = nil, api_host = nil)
  @token    = token || ENV["APPETIZE_API_TOKEN"]
  @api_host = api_host || "api.appetize.io"

  raise "Appetize Token Missing" if @token.nil?
end

Instance Method Details

#create(path, platform) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/appetize/api.rb', line 14

def create(path, platform)
  url = "https://#{@api_host}/v1/apps"
  auth = { username: @token, password: "" }
  body = { platform: platform, file: File.open(path) }

  HTTParty.post(url, body: body, basic_auth: auth)
end

#delete(public_key) ⇒ Object


30
31
32
33
34
35
# File 'lib/appetize/api.rb', line 30

def delete(public_key)
  url = "https://#{@api_host}/v1/apps/#{public_key}"
  auth = { username: @token, password: "" }

  HTTParty.delete(url, basic_auth: auth)
end

#update(path, public_key) ⇒ Object


22
23
24
25
26
27
28
# File 'lib/appetize/api.rb', line 22

def update(path, public_key)
  url = "https://#{@api_host}/v1/apps/#{public_key}"
  auth = { username: @token, password: "" }
  body = { file: File.open(path) }

  HTTParty.post(url, body: body, basic_auth: auth)
end