Class: Mesmerize::Client

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

Constant Summary collapse

HOSTNAME =
'mesmerizeapp.com'

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

HOSTNAME = ‘localhost:5000’



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mesmerize/client.rb', line 10

def initialize(api_key = nil)
  @connection = Faraday.new(:url => "https://#{HOSTNAME}") do |builder|
    builder.request :multipart
    builder.request :url_encoded
    builder.use FaradayMiddleware::FollowRedirects

    builder.response :json, :content_type => /\bjson$/

    builder.adapter :net_http
  end

  @connection.headers['X-Mesmerize-API-Key'] = api_key if api_key
end

Instance Method Details

#get_app(app) ⇒ Object



53
54
55
56
57
# File 'lib/mesmerize/client.rb', line 53

def get_app(app)
  @connection.get("/api/apps/#{app}").on_complete do |env|
    yield env[:status], env[:body] if block_given?
  end
end

#get_appsObject



47
48
49
50
51
# File 'lib/mesmerize/client.rb', line 47

def get_apps
  @connection.get("/api/accounts").on_complete do |env|
    yield env[:status], env[:body] if block_given?
  end
end

#post_account(name, email, password) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mesmerize/client.rb', line 35

def (name, email, password)
  params = {
    :name => name,
    :email => email,
    :password => password
  }

  @connection.post("/api/accounts", params).on_complete do |env|
    yield env[:status], env[:body] if block_given?
  end
end

#post_app(app) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/mesmerize/client.rb', line 59

def post_app(app)
  params = {
    :name => app
  }

  @connection.post("/api/apps", params).on_complete do |env|
    yield env[:status], env[:body] if block_given?
  end
end

#post_release(app, params, file) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mesmerize/client.rb', line 69

def post_release(app, params, file)
  @connection.post("/api/apps/#{app}/releases", params).on_complete do |env|
    if (200...300).include? env[:status]
      params = env[:body]["params"]
      params[:file] = Faraday::UploadIO.new(file, 'application/octet-stream')

      response = @connection.post(env[:body]["url"], params)

      yield response[:status], response[:body] if block_given?
    else
      yield env[:status], env[:body] if block_given?
    end
  end
end

#post_session(email, password) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/mesmerize/client.rb', line 24

def post_session(email, password)
  params = {
    :email => email,
    :password => password
  }

  @connection.post("/api/sessions", params).on_complete do |env|
    yield env[:status], env[:body] if block_given?
  end
end