heroku-client 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in heroku-client.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "rake"
8
+ end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/rodrigosaito/heroku-client.png?branch=master)](http://travis-ci.org/rodrigosaito/heroku-client)
2
+
1
3
  # Heroku::Client
2
4
 
3
5
  Client for accessing heroku api from ruby applications
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
@@ -6,11 +6,18 @@ require "heroku-client/json_util"
6
6
  require "heroku-client/heroku_obj"
7
7
  require "heroku-client/http"
8
8
  require "heroku-client/api"
9
+ require "heroku-client/api_test"
9
10
 
10
11
  module Heroku
11
12
  module Client
12
13
  def self.create(apikey)
14
+ return ApiTest.new if @test_mode
15
+
13
16
  Api.new(apikey)
14
17
  end
18
+
19
+ def self.test_mode=(test_mode)
20
+ @test_mode = test_mode
21
+ end
15
22
  end
16
23
  end
@@ -0,0 +1,45 @@
1
+ module Heroku
2
+ module Client
3
+ class ApiTest
4
+
5
+ def apps
6
+ json_fake_1 = <<-JSON
7
+ {
8
+ "id": 1000000,
9
+ "name": "example",
10
+ "create_status": "complete",
11
+ "created_at": "2011/01/01 00:00:00 -0700",
12
+ "stack": "bamboo-ree-1.8.7",
13
+ "requested_stack": null,
14
+ "repo_migrate_status": "complete",
15
+ "slug_size": 1000000,
16
+ "repo_size": 1000000,
17
+ "dynos": 1,
18
+ "workers": 0
19
+ }
20
+ JSON
21
+
22
+ json_fake_2 = <<-JSON
23
+ {
24
+ "id": 1000001,
25
+ "name": "example_2",
26
+ "create_status": "complete",
27
+ "created_at": "2011/01/01 00:00:00 -0700",
28
+ "stack": "bamboo-ree-1.8.7",
29
+ "requested_stack": null,
30
+ "repo_migrate_status": "complete",
31
+ "slug_size": 1000000,
32
+ "repo_size": 1000000,
33
+ "dynos": 1,
34
+ "workers": 0
35
+ }
36
+ JSON
37
+
38
+ [ json_fake_1, json_fake_2 ].map do |json|
39
+ HerokuObj.new JSON.parse(json)
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -9,7 +9,11 @@ module Heroku
9
9
 
10
10
  super.method_missing(method, args) unless @json.has_key?(attribute)
11
11
 
12
- @json["#{attribute}"]
12
+ attr_value = @json["#{attribute}"]
13
+
14
+ attr_value = HerokuObj.new(attr_value) if attr_value.is_a? Hash
15
+
16
+ attr_value
13
17
  end
14
18
 
15
19
  def initialize(json)
@@ -46,12 +46,7 @@ module Heroku
46
46
  raise UnknownError
47
47
  end
48
48
 
49
- parsed = JSON.parse(resp.body)
50
- parsed = parsed.map { |o| HerokuObj.new(o) } if parsed.is_a? Array
51
-
52
- parsed = HerokuObj.new parsed if parsed.is_a? Hash
53
-
54
- parsed
49
+ json_util.parse_response resp.body
55
50
  end
56
51
 
57
52
  private
@@ -60,28 +55,28 @@ module Heroku
60
55
  end
61
56
  end
62
57
 
63
- class UnauthorizedError < Exception
58
+ class UnauthorizedError < StandardError
64
59
  end
65
60
 
66
- class PaymentRequiredError < Exception
61
+ class PaymentRequiredError < StandardError
67
62
  end
68
63
 
69
- class ForbiddenError < Exception
64
+ class ForbiddenError < StandardError
70
65
  end
71
66
 
72
- class NotFoundError < Exception
67
+ class NotFoundError < StandardError
73
68
  end
74
69
 
75
- class PreConditionFailedError < Exception
70
+ class PreConditionFailedError < StandardError
76
71
  end
77
72
 
78
- class UnprocessableEntityError < Exception
73
+ class UnprocessableEntityError < StandardError
79
74
  end
80
75
 
81
- class LockedError < Exception
76
+ class LockedError < StandardError
82
77
  end
83
78
 
84
- class UnknownError < Exception
79
+ class UnknownError < StandardError
85
80
  end
86
81
  end
87
82
  end
@@ -21,6 +21,14 @@ module Heroku
21
21
  body
22
22
  end
23
23
 
24
+ def parse_response(body)
25
+ parsed = JSON.parse(body)
26
+
27
+ return parsed.map { |o| HerokuObj.new(o) } if parsed.is_a? Array
28
+
29
+ HerokuObj.new parsed
30
+ end
31
+
24
32
  end
25
33
  end
26
34
  end
@@ -1,5 +1,5 @@
1
1
  module Heroku
2
2
  module Client
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe Heroku::Client::ApiTest do
4
+
5
+ describe "#apps" do
6
+ let(:apps) { subject.apps }
7
+
8
+ it "returns 2 fake apps" do
9
+ apps.size.should eq(2)
10
+ end
11
+
12
+ it "returns an Array" do
13
+ apps.should be_a(Array)
14
+ end
15
+
16
+ it "returns an Array os HerokuObj" do
17
+ apps.each do |a|
18
+ a.should be_a(Heroku::Client::HerokuObj)
19
+ end
20
+ end
21
+
22
+ it "returns example as first app" do
23
+ apps.first.name.should eq("example")
24
+ end
25
+
26
+ it "returns example_2 as second app" do
27
+ apps.last.name.should eq("example_2")
28
+ end
29
+
30
+ context "when a valid name is passed as parameter" do
31
+
32
+ end
33
+ end
34
+
35
+ end
@@ -1,13 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Heroku::Client::JSONUtil do
4
+ let(:json_util) { Heroku::Client::JSONUtil.new }
4
5
 
5
6
  describe "#parse_error" do
6
- let(:json) { Heroku::Client::JSONUtil.new }
7
7
 
8
8
  shared_examples "error parser" do |body, expected|
9
9
  it "should parse error" do
10
- json.parse_error(body).should eq(expected)
10
+ json_util.parse_error(body).should eq(expected)
11
11
  end
12
12
  end
13
13
 
@@ -26,4 +26,46 @@ describe Heroku::Client::JSONUtil do
26
26
  end
27
27
  end
28
28
 
29
+ describe "#parse_response" do
30
+ describe "when json object" do
31
+ let(:json) { '{"string_attr": "string value", "number_attr": 10, "boolean_attr": true, "nested_attr": {"nested_attr": "nested_value"}}' }
32
+
33
+ let(:result) { json_util.parse_response json }
34
+
35
+ it "returns a HerokuObject" do
36
+ result.should be_a(Heroku::Client::HerokuObj)
37
+ end
38
+
39
+ it "parses a string attribute" do
40
+ result.string_attr.should eq("string value")
41
+ end
42
+
43
+ it "parses a number attribute" do
44
+ result.number_attr.should eq(10)
45
+ end
46
+
47
+ it "parses a boolean attribute" do
48
+ result.boolean_attr?.should be_true
49
+ end
50
+
51
+ it "parses nested objects" do
52
+ result.nested_attr.should be_a(Heroku::Client::HerokuObj)
53
+ end
54
+ end
55
+
56
+ describe "when json array" do
57
+ let(:json) { '[{"json_obj": "value"}]' }
58
+
59
+ let(:result) { json_util.parse_response json }
60
+
61
+ it "parses an array" do
62
+ result.should be_a(Array)
63
+ end
64
+
65
+ it "array contains HerokuObjects" do
66
+ result.first.should be_a(Heroku::Client::HerokuObj)
67
+ end
68
+ end
69
+ end
70
+
29
71
  end
@@ -10,6 +10,18 @@ describe Heroku::Client do
10
10
  it "creates an Api object that has the apikey attribute" do
11
11
  Heroku::Client.create("apikey").apikey.should eq("apikey")
12
12
  end
13
+
14
+ context "when test_mode is set" do
15
+ before do
16
+ Heroku::Client.test_mode = true
17
+ end
18
+
19
+ it "creates an ApiTest object" do
20
+ Heroku::Client::create("apikey").should be_a(Heroku::Client::ApiTest)
21
+
22
+ end
23
+
24
+ end
13
25
  end
14
26
 
15
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-29 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -100,6 +100,7 @@ extra_rdoc_files: []
100
100
  files:
101
101
  - .gitignore
102
102
  - .rspec
103
+ - .travis.yml
103
104
  - Gemfile
104
105
  - Guardfile
105
106
  - LICENSE
@@ -108,11 +109,13 @@ files:
108
109
  - heroku-client.gemspec
109
110
  - lib/heroku-client.rb
110
111
  - lib/heroku-client/api.rb
112
+ - lib/heroku-client/api_test.rb
111
113
  - lib/heroku-client/heroku_obj.rb
112
114
  - lib/heroku-client/http.rb
113
115
  - lib/heroku-client/json_util.rb
114
116
  - lib/heroku-client/version.rb
115
117
  - spec/heroku-client/api_spec.rb
118
+ - spec/heroku-client/api_test_spec.rb
116
119
  - spec/heroku-client/heroku_obj_spec.rb
117
120
  - spec/heroku-client/http_spec.rb
118
121
  - spec/heroku-client/json_util_spec.rb
@@ -131,12 +134,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
134
  - - ! '>='
132
135
  - !ruby/object:Gem::Version
133
136
  version: '0'
137
+ segments:
138
+ - 0
139
+ hash: 103495294675291456
134
140
  required_rubygems_version: !ruby/object:Gem::Requirement
135
141
  none: false
136
142
  requirements:
137
143
  - - ! '>='
138
144
  - !ruby/object:Gem::Version
139
145
  version: '0'
146
+ segments:
147
+ - 0
148
+ hash: 103495294675291456
140
149
  requirements: []
141
150
  rubyforge_project:
142
151
  rubygems_version: 1.8.24
@@ -145,10 +154,10 @@ specification_version: 3
145
154
  summary: Client for accessing heroku api
146
155
  test_files:
147
156
  - spec/heroku-client/api_spec.rb
157
+ - spec/heroku-client/api_test_spec.rb
148
158
  - spec/heroku-client/heroku_obj_spec.rb
149
159
  - spec/heroku-client/http_spec.rb
150
160
  - spec/heroku-client/json_util_spec.rb
151
161
  - spec/heroku-client_spec.rb
152
162
  - spec/responses/api.rb
153
163
  - spec/spec_helper.rb
154
- has_rdoc: