Class: CoderCompanion::API
- Inherits:
-
Object
- Object
- CoderCompanion::API
- Defined in:
- lib/codercompanion/api.rb
Constant Summary collapse
- STATUS_OK =
200- USER_NOT_FOUND =
461- PROJECT_NOT_FOUND =
510- GENERIC_ERROR =
500
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #get_temporary_access_key ⇒ Object
-
#initialize(config = {}) ⇒ API
constructor
A new instance of API.
- #notify_s3_upload(key) ⇒ Object
- #upload(file) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ API
Returns a new instance of API.
10 11 12 |
# File 'lib/codercompanion/api.rb', line 10 def initialize(config={}) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/codercompanion/api.rb', line 8 def config @config end |
Instance Method Details
#get_temporary_access_key ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/codercompanion/api.rb', line 28 def get_temporary_access_key begin RestClient.post("#{config[:host]}/project/get_temporary_access_key.json", :access_key => config[:access_key], :access_id => config[:access_id]) { |response, request, result, &block| return (response.code == STATUS_OK) ? response : nil } rescue return nil end end |
#notify_s3_upload(key) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/codercompanion/api.rb', line 40 def notify_s3_upload(key) begin RestClient.post("#{config[:host]}/project/notify_project_upload.json", :s3_key => key, :access_key => config[:access_key], :access_id => config[:access_id]) { |response, request, result, &block| return (response.code == STATUS_OK) ? response : nil } rescue return nil end end |
#upload(file) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/codercompanion/api.rb', line 14 def upload(file) response = nil begin response = RestClient.post(config[:host] + '/update_project.json', :myfile => File.new(file),# /Users/oseghale/Projects/JinglePage/JingleParser/test_upload.jingle'), :access_key => config[:access_key], :access_id => config[:access_id]) { |response, request, result, &block| return response.code || nil } rescue return GENERIC_ERROR end end |