Class: Sunrise::Client
- Inherits:
-
Object
- Object
- Sunrise::Client
- Defined in:
- lib/sunrise.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#login ⇒ Object
Returns the value of attribute login.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(login, password, host = 'sunrisehq.com', port = '80') ⇒ Client
constructor
A new instance of Client.
-
#teams ⇒ Object
Fetch an array of teams from an account.
- #upload(file, team, name = nil) ⇒ Object
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(login, password, host = 'sunrisehq.com', port = '80') @login, @password, @host, @port = login, password, host, port end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/sunrise.rb', line 7 def host @host end |
#login ⇒ Object
Returns the value of attribute login.
7 8 9 |
# File 'lib/sunrise.rb', line 7 def login @login end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/sunrise.rb', line 7 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/sunrise.rb', line 7 def port @port end |
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/sunrise.rb', line 7 def response @response end |
Instance Method Details
#teams ⇒ Object
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 |