Skip to content

Commit

Permalink
Switching to rest wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
iced committed Feb 13, 2012
1 parent 80b2d68 commit 36e36c2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -2,6 +2,7 @@ source "http://rubygems.org"

gem 'zip'
gem 'rest-client'
gem 'rest'
gem 'json'

group :development do
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -12,6 +12,9 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rest (0.1.0)
rest-client
rest-client
rest-client (1.6.7)
mime-types (>= 1.16)
zip (2.0.2)
Expand All @@ -23,5 +26,6 @@ DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.8.3)
json
rest
rest-client
zip
25 changes: 15 additions & 10 deletions lib/iron_worker_ng/api_client.rb
@@ -1,4 +1,5 @@
require 'rest_client'
require 'rest-client'
require 'rest'
require 'json'

module IronWorkerNG
Expand All @@ -11,28 +12,32 @@ def initialize(project_id, token)
@token = token

@url = 'https://worker-aws-us-east-1.iron.io/2/'

@rest = Rest::Client.new
end

def common_request_hash
{
:accept => 'json',
:content_type => 'json',
:authorization => "OAuth #{@token}",
:user_agent => 'IronWorker Ruby Client NG'
'Content-Type' => 'application/json',
'Authorization' => "OAuth #{@token}",
'User-Agent' => 'IronWorker Ruby Client NG'
}
end

def get(method, params = {})
request_hash = common_request_hash
request_hash = {}
request_hash[:headers] = common_request_hash
request_hash[:params] = params

RestClient.get(@url + method, request_hash)
@rest.get(@url + method, request_hash)
end

def post(method, params = {})
request_hash = common_request_hash
request_hash = {}
request_hash[:headers] = common_request_hash
request_hash[:body] = params.to_json

RestClient.post(@url + method, params.to_json, request_hash)
@rest.post(@url + method, request_hash)
end

def post_file(method, file, params = {})
Expand All @@ -47,7 +52,7 @@ def codes_list
response = get("projects/#{@project_id}/codes")

return nil if response.code != 200
JSON.parse(response.to_s)['codes']
JSON.parse(response.body)['codes']
end

def codes_create(name, file, runtime, runner)
Expand Down
2 changes: 2 additions & 0 deletions lib/iron_worker_ng/client.rb
Expand Up @@ -4,6 +4,8 @@

module IronWorkerNG
class Client
attr_reader :api

def initialize(project_id, token)
@api = IronWorkerNG::APIClient.new(project_id, token)
end
Expand Down

0 comments on commit 36e36c2

Please sign in to comment.