one_sky 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,12 +11,22 @@ module OneSky
11
11
 
12
12
  # Returns details about the project.
13
13
  def details
14
- get("/details")["project"]
14
+ get("/project/details")["project"]
15
+ end
16
+
17
+ # Returns available types to be specified when creating a new the project.
18
+ def types
19
+ get("/project/types")["types"]
15
20
  end
16
21
 
17
22
  # Returns an array of available languages.
18
23
  def languages
19
- get("/languages")["languages"]
24
+ get("/project/languages")["languages"]
25
+ end
26
+
27
+ # Returns info about your account.
28
+ def info
29
+ get("/info")["application"]
20
30
  end
21
31
 
22
32
  # Returns the SSO URL for the given unique_id
@@ -89,22 +99,27 @@ module OneSky
89
99
  def hash_to_params(hash)
90
100
  hash.inject({}) { |o, (k,v)| o[k.to_s.gsub("_", "-").to_sym] = v; o }
91
101
  end
92
-
102
+
103
+ def authorization_params
104
+ timestamp = Time.now.to_i.to_s
105
+ {:project => @name, :"api-key" => @api_key, :timestamp => timestamp, :"dev-hash" => Digest::MD5.hexdigest(timestamp + @api_secret)}
106
+ end
107
+
93
108
  def get(path, params = {}, options = {:content_type => "text/plain; charset=UTF-8"})
94
- params = {:"api-key" => @api_key, :"api-secret" => @api_secret, :"project" => @name}.merge(params)
109
+ params = authorization_params.merge(params)
95
110
  parse_response(RestClient.get([API_ROOT_URL, path].join, {:params => params}.merge(options)))
96
111
  end
97
112
 
98
113
  def post(path, params = {}, options = {:content_type => "text/plain; charset=UTF-8"})
99
- params = {:"api-key" => @api_key, :"api-secret" => @api_secret, :"project" => @name}.merge(params)
114
+ params = authorization_params.merge(params)
100
115
  parse_response(RestClient.post([API_ROOT_URL, path].join, params.merge(options)))
101
116
  end
102
117
 
103
118
  def parse_response(response)
104
- raise ApiHttpResponseError, "HTTP response status code: #{response.code.inspect}." unless response.code.eql?(200)
105
119
  # Do not post-process response if it isn't JSON. (ie. Binary file returned from /output_mo.)
106
120
  return response.body unless response.headers[:content_type] =~ /json/
107
121
  response_hash = JSON.parse(response)
122
+
108
123
  raise ApiError, response.body if response_hash.has_key?("response") and response_hash["response"] != "ok"
109
124
  response_hash
110
125
  end
@@ -1,3 +1,3 @@
1
1
  module OneSky
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/one_sky.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'json'
2
2
  require 'rest_client'
3
+ require 'digest/md5'
3
4
 
4
5
  module OneSky
5
6
  API_ROOT_URL = "https://api.oneskyapp.com/1"
6
7
 
7
8
  autoload :Project, 'one_sky/project'
8
9
 
9
- %w[ApiHttpResponseError ApiError].each { |e| const_set(e, Class.new(StandardError)) }
10
+ %w[ApiError].each { |e| const_set(e, Class.new(StandardError)) }
10
11
  end
data/spec/project_spec.rb CHANGED
@@ -17,7 +17,7 @@ describe "Project" do
17
17
 
18
18
  it "raises an error when incorrect API credentials are passed." do
19
19
  @project.api_secret = "wrong secret"
20
- lambda { @project.details }.should raise_error OneSky::ApiError
20
+ lambda { @project.details }.should raise_error RestClient::Exception
21
21
  end
22
22
 
23
23
  describe "#details" do
@@ -26,9 +26,27 @@ describe "Project" do
26
26
  end
27
27
  end
28
28
 
29
+ describe "#types" do
30
+ it "returns an array." do
31
+ types = @project.types
32
+ types.should be_an(Array)
33
+ types.size.should > 0
34
+ end
35
+ end
36
+
29
37
  describe "#languages" do
30
38
  it "returns an array." do
31
- @project.languages.should be_an(Array)
39
+ langs = @project.languages
40
+ langs.should be_an(Array)
41
+ langs.size.should > 0
42
+ end
43
+ end
44
+
45
+ describe "#info" do
46
+ it "returns a hash." do
47
+ info = @project.info
48
+ info.should be_an(Hash)
49
+ info.has_key?("name").should be_true
32
50
  end
33
51
  end
34
52
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Junjun Olympia
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-03 00:00:00 +08:00
17
+ date: 2011-02-10 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency