class Upscrn::Client
Attributes
auth_token[RW]
auth_token[RW]
params[RW]
resources[RW]
Public Class Methods
config() { |self| ... }
click to toggle source
# File lib/upscrn_client/client.rb, line 7 def config yield self end
new(auth_token = nil)
click to toggle source
# File lib/upscrn_client/client.rb, line 67 def initialize(auth_token = nil) @auth_token = auth_token || self.class.auth_token @resources = [] @params = {} end
projects(auth_token)
click to toggle source
return a list of projects for a given user list is returned in json format
# File lib/upscrn_client/client.rb, line 47 def projects(auth_token) puts "DEPRECATED: will be removed on version 0.3" perform('get', 'projects', auth_token) end
upload_screenshot(filename, auth_token, options = {})
click to toggle source
Upload a screenshot to the upscrn server. Pass :project_id in the options to upload to a particular project
# File lib/upscrn_client/client.rb, line 17 def upload_screenshot(filename, auth_token, options = {}) puts "DEPRECATED: will be removed on version 0.3" #puts "filepath: #{filepath}" @result = Hash.new @result['success'] = true file = File.open filename, 'r' begin if options[:project_id] post_response = perform("post", "projects/#{options[:project_id]}/screenshots", auth_token, {:screenshot => {:image => @image}}) else post_response = perform('post', 'screenshots', auth_token, {:screenshot => {:image => file}}) end #puts "response: #{post_response}" @url = post_response["url"] @result['success'] = true @result['url'] = @url #puts "url = #{@url}" @url rescue Exception => e #puts "Exception! #{e.message}" @result['success'] = false @result['error'] = e.message.to_s end @result end
Private Class Methods
perform(verb,action,auth_token, params={})
click to toggle source
# File lib/upscrn_client/client.rb, line 54 def perform(verb,action,auth_token, params={}) action = [action, 'json'].join('.') url = ['http://upscrn.com', action].join('/') url = url + "?auth_token=#{auth_token}" JSON.parse(RestClient.send(verb,url,params).body) end
Public Instance Methods
clean()
click to toggle source
# File lib/upscrn_client/client.rb, line 150 def clean tap do @resources = [] @params = {} end end
comment(params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 123 def comment(params = {}) tap do @resources += ['comments'] @params.merge!(params) end end
comments(params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 88 def comments(params = {}) tap do @resources += ['comments'] @params.merge!(params) end end
get(clean = true)
click to toggle source
# File lib/upscrn_client/client.rb, line 132 def get(clean = true) result = client[build_path(@auth_token,@resources,@params)].get self.clean if clean JSON.parse result end
post(clean = true)
click to toggle source
# File lib/upscrn_client/client.rb, line 138 def post(clean = true) result = client[build_path(@auth_token,@resources)].post(@params) self.clean if clean JSON.parse result end
project(id , params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 102 def project(id , params = {}) tap do @resources = ['projects',id] @params.merge!(params) end end
projects(params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 74 def projects(params = {}) tap do @resources = ['projects'] @params.merge!(params) end end
put(clean = true)
click to toggle source
# File lib/upscrn_client/client.rb, line 144 def put(clean = true) result = client[build_path(@auth_token,@resources)].put(@params) self.clean if clean JSON.parse result end
screenshot(id , params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 109 def screenshot(id , params = {}) tap do @resources += ['screenshots',id] @params.merge!(params) end end
screenshots(params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 81 def screenshots(params = {}) tap do @resources += ['screenshots'] @params.merge!(params) end end
video(id , params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 116 def video(id , params = {}) tap do @resources += ['videos',id] @params.merge!(params) end end
videos(params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 95 def videos(params = {}) tap do @resources += ['videos'] @params.merge!(params) end end
Private Instance Methods
build_path(auth_token,resources , params = {})
click to toggle source
# File lib/upscrn_client/client.rb, line 163 def build_path(auth_token,resources , params = {}) url = resources.join('/') url += '.json' url += "?" + params.merge(:auth_token => auth_token).to_a.map{|p| p.join('=')}.join('&') puts "Path built: #{url}" URI.encode(url) end
client()
click to toggle source
# File lib/upscrn_client/client.rb, line 159 def client @client ||= RestClient::Resource.new('http://upscrn.com') end