Class: Sunrise::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login, password, host = 'sunrisehq.com', port = '80') ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/sunrise.rb', line 8

def initialize(, password, host = 'sunrisehq.com', port = '80')
  @login, @password, @host, @port = , password, host, port
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#loginObject

Returns the value of attribute login.



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

def 
  @login
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#teamsObject

Fetch an array of teams from an account



27
28
29
30
31
32
33
# File 'lib/sunrise.rb', line 27

def teams
  url = "http://#{@login}:#{@password}@#{@host}:#{@port}/team.json"
  @response = RestClient.get url#, :content_type => :json, :accept => :json
  teams = []
  JSON.parse(@response).each { |team| teams << team['team']['subdomain'] }
  return teams
end

#upload(file, team, name = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sunrise.rb', line 12

def upload(file, team, name = nil)
  file = File.new(file) if file.is_a? String
  name = default_name(file) unless name
  url = "http://#{@login}:#{@password}@#{team}.#{@host}:#{@port}/upload.json"
  @response = RestClient.post url,
    :item => {
      :type  => 'Screenshot',
      :image => file,
      :name  => name,
    },
    :content_type => :json,
    :accept => :json
end