cobregratis 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "activeresource", ">= 2.1"
5
+ gem "activesupport", ">= 2.1"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.3.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.5)
5
+ activesupport (= 3.0.5)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4)
8
+ activeresource (3.0.5)
9
+ activemodel (= 3.0.5)
10
+ activesupport (= 3.0.5)
11
+ activesupport (3.0.5)
12
+ builder (2.1.2)
13
+ diff-lcs (1.1.2)
14
+ git (1.2.5)
15
+ i18n (0.5.0)
16
+ jeweler (1.5.2)
17
+ bundler (~> 1.0.0)
18
+ git (>= 1.2.5)
19
+ rake
20
+ rake (0.8.7)
21
+ rcov (0.9.9)
22
+ rspec (2.3.0)
23
+ rspec-core (~> 2.3.0)
24
+ rspec-expectations (~> 2.3.0)
25
+ rspec-mocks (~> 2.3.0)
26
+ rspec-core (2.3.1)
27
+ rspec-expectations (2.3.0)
28
+ diff-lcs (~> 1.1.2)
29
+ rspec-mocks (2.3.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ activeresource (>= 2.1)
36
+ activesupport (>= 2.1)
37
+ bundler (~> 1.0.0)
38
+ jeweler (~> 1.5.2)
39
+ rcov
40
+ rspec (~> 2.3.0)
data/README.mkdn CHANGED
@@ -44,6 +44,14 @@ This code is free to be used under the terms of the [MIT license][mit].
44
44
 
45
45
  Comments are welcome. Send your feedback through the [issue tracker on GitHub][i]
46
46
 
47
+ ## Contributors
48
+
49
+ Special thanks to:
50
+
51
+ ### **Tapajós**
52
+
53
+ Github: [http://github.com/tapajos](http://github.com/tapajos)
54
+
47
55
  ## Author
48
56
 
49
57
  ### **Rafael Lima**
data/Rakefile CHANGED
@@ -1,12 +1,22 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
2
10
  require 'rake'
3
11
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "cobregratis"
8
- gem.summary = %Q{Ruby Wrapper around Cobre Grátis API}
9
- gem.description = %{
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "cobregratis"
16
+ gem.homepage = "http://github.com/rafaelp/cobregratis"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby Wrapper around Cobre Grátis API}
19
+ gem.description = %{
10
20
  Cobre Grátis
11
21
 
12
22
  Configure by adding the following:
@@ -15,59 +25,28 @@ require 'cobregratis'
15
25
  Cobregratis::Base.site = 'https://app.cobregratis.com.br/'
16
26
  Cobregratis::Base.user = 'your_api_username'
17
27
  Cobregratis::Base.user = 'your_api_password'
18
- }
19
- gem.email = "contato@rafael.adm.br"
20
- gem.homepage = "http://github.com/rafaelp/cobregratis"
21
- gem.authors = ["Rafael Lima"]
22
- gem.add_development_dependency "rspec", ">= 1.2.9"
23
- gem.add_dependency('activeresource', '>= 2.1')
24
- gem.add_dependency('activesupport', '>= 2.1')
25
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
26
- end
27
- Jeweler::GemcutterTasks.new
28
- rescue LoadError
29
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
28
+ }
29
+ gem.email = "contato@rafael.adm.br"
30
+ gem.authors = ["Rafael Lima"]
31
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
32
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
33
+ gem.add_runtime_dependency 'activeresource', '>= 2.1'
34
+ gem.add_runtime_dependency 'activesupport', '>= 2.1'
35
+ gem.add_development_dependency 'rspec', '~> 2.3.0'
30
36
  end
37
+ Jeweler::RubygemsDotOrgTasks.new
31
38
 
32
- require 'spec/rake/spectask'
33
- Spec::Rake::SpecTask.new(:spec) do |spec|
34
- spec.libs << 'lib' << 'spec'
35
- spec.spec_files = FileList['spec/**/*_spec.rb']
39
+ require 'rspec/core'
40
+ require 'rspec/core/rake_task'
41
+ RSpec::Core::RakeTask.new(:spec) do |spec|
42
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
43
  end
37
44
 
38
- Spec::Rake::SpecTask.new(:rcov) do |spec|
39
- spec.libs << 'lib' << 'spec'
45
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
40
46
  spec.pattern = 'spec/**/*_spec.rb'
41
47
  spec.rcov = true
42
48
  end
43
49
 
44
- task :spec => :check_dependencies
45
-
46
- begin
47
- require 'reek/adapters/rake_task'
48
- Reek::RakeTask.new do |t|
49
- t.fail_on_error = true
50
- t.verbose = false
51
- t.source_files = 'lib/**/*.rb'
52
- end
53
- rescue LoadError
54
- task :reek do
55
- abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
56
- end
57
- end
58
-
59
- begin
60
- require 'roodi'
61
- require 'roodi_task'
62
- RoodiTask.new do |t|
63
- t.verbose = false
64
- end
65
- rescue LoadError
66
- task :roodi do
67
- abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
68
- end
69
- end
70
-
71
50
  task :default => :spec
72
51
 
73
52
  require 'rake/rdoctask'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.1
data/lib/cachable.rb CHANGED
@@ -64,13 +64,13 @@ module Cachable
64
64
  alias_method_chain :get, :cache
65
65
 
66
66
  def put_with_cache(path, body = '', headers = {})
67
- cache_store.delete(cache_key(path))
67
+ cache_store.delete(cache_key(path)) if is_caching?
68
68
  put_without_cache(path, body, headers)
69
69
  end
70
70
  alias_method_chain :put, :cache
71
71
 
72
72
  def delete_with_cache(path, headers = {})
73
- cache_store.delete(cache_key(path))
73
+ cache_store.delete(cache_key(path)) if is_caching?
74
74
  delete_without_cache(path, headers)
75
75
  end
76
76
  alias_method_chain :delete, :cache
@@ -0,0 +1,4 @@
1
+ module Cobregratis
2
+ class BankBillet < Base
3
+ end
4
+ end
data/lib/cobregratis.rb CHANGED
@@ -2,4 +2,4 @@ require 'active_resource'
2
2
  $:.unshift(File.dirname(__FILE__))
3
3
 
4
4
  require 'cobregratis/base'
5
- require 'cobregratis/billet'
5
+ require 'cobregratis/bank_billet'
@@ -23,7 +23,6 @@ end
23
23
  describe CachedResource do
24
24
  before(:all) do
25
25
  CachedResource.site = 'http://example.com.i:3000'
26
- CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :memory_store
27
26
  end
28
27
 
29
28
  after(:all) do
@@ -35,50 +34,89 @@ describe CachedResource do
35
34
  @key = :key
36
35
  CachedResource.connection.stub!(:cache_key).and_return(@key)
37
36
  end
38
-
39
- context "when a cached response is available" do
40
- before(:each) do
41
- CachedResource.connection.cache_store.write(@key, @thing.attributes)
37
+
38
+ context "when cache is configured" do
39
+ before(:all) do
40
+ CachedResource.connection.cache_store = ActiveSupport::Cache.lookup_store :memory_store
42
41
  end
42
+
43
+ context "when a cached response is available" do
44
+ before(:each) do
45
+ CachedResource.connection.cache_store.write(@key, @thing.attributes)
46
+ end
43
47
 
44
- it "should NOT make a request to the RESTful server" do
45
- CachedResource.connection.should_not_receive(:get_without_cache)
46
- CachedResource.find(1)
47
- end
48
+ it "should NOT make a request to the RESTful server" do
49
+ CachedResource.connection.should_not_receive(:get_without_cache)
50
+ CachedResource.find(1)
51
+ end
48
52
 
49
- it "should read from the cache" do
50
- CachedResource.find(1).should == @thing
51
- end
53
+ it "should read from the cache" do
54
+ CachedResource.find(1).should == @thing
55
+ end
52
56
 
53
- it "should delete from the cache when an object is DELETEd" do
54
- CachedResource.connection.should_receive(:delete_without_cache)
55
- CachedResource.delete(1)
56
- CachedResource.connection.cache_store.read(@key).should == nil
57
- end
57
+ it "should delete from the cache when an object is DELETEd" do
58
+ CachedResource.connection.should_receive(:delete_without_cache)
59
+ CachedResource.delete(1)
60
+ CachedResource.connection.cache_store.read(@key).should == nil
61
+ end
58
62
 
59
- it "should delete from the cache when an object is modified" do
60
- thing = CachedResource.find(1)
61
- thing.stub(:load_attributes_from_response).and_return(@thing.attributes)
62
- CachedResource.connection.should_receive(:put_without_cache)
63
- thing.save
64
- CachedResource.connection.cache_store.read(@key).should == nil
63
+ it "should delete from the cache when an object is modified" do
64
+ thing = CachedResource.find(1)
65
+ thing.stub(:load_attributes_from_response).and_return(@thing.attributes)
66
+ CachedResource.connection.should_receive(:put_without_cache)
67
+ thing.save
68
+ CachedResource.connection.cache_store.read(@key).should == nil
69
+ end
70
+ end
71
+
72
+ context "when a cached response is NOT available" do
73
+ before(:each) do
74
+ CachedResource.connection.cache_store.delete(@key)
75
+ end
76
+
77
+ it "SHOULD perform an ActiveResource request" do
78
+ CachedResource.connection.should_receive(:get_without_cache).and_return(@thing.attributes)
79
+ CachedResource.find(1)
80
+ end
81
+
82
+ it "should cache the response using the caching key" do
83
+ CachedResource.connection.should_receive(:get_without_cache).and_return(@thing.attributes)
84
+ CachedResource.find(1)
85
+ CachedResource.connection.cache_store.read(@key).should == @thing.attributes
86
+ end
65
87
  end
66
88
  end
67
89
 
68
- context "when a cached response is NOT available" do
69
- before(:each) do
70
- CachedResource.connection.cache_store.delete(@key)
90
+ context "when cache is not configured" do
91
+ before(:all) do
92
+ CachedResource.connection.cache_store = nil
71
93
  end
72
-
94
+
73
95
  it "SHOULD perform an ActiveResource request" do
74
96
  CachedResource.connection.should_receive(:get_without_cache).and_return(@thing.attributes)
75
97
  CachedResource.find(1)
76
98
  end
99
+
100
+ it "should not raise exception finding object" do
101
+ lambda {
102
+ CachedResource.connection.should_receive(:get_without_cache).and_return(@thing.attributes)
103
+ CachedResource.find(1)
104
+ }.should_not raise_exception
105
+ end
77
106
 
78
- it "should cache the response using the caching key" do
79
- CachedResource.connection.should_receive(:get_without_cache).and_return(@thing.attributes)
80
- CachedResource.find(1)
81
- CachedResource.connection.cache_store.read(@key).should == @thing.attributes
107
+ it "should not raise exception when an object is DELETEd" do
108
+ lambda {
109
+ CachedResource.connection.should_receive(:delete_without_cache)
110
+ CachedResource.delete(1)
111
+ }.should_not raise_exception
112
+ end
113
+
114
+ it "should not raise exception when an object is modified" do
115
+ lambda {
116
+ @thing.stub(:load_attributes_from_response).and_return(@thing.attributes)
117
+ CachedResource.connection.should_receive(:put_without_cache)
118
+ @thing.save
119
+ }.should_not raise_exception
82
120
  end
83
121
  end
84
122
  end
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe Cobregratis::Billet do
3
+ describe Cobregratis::BankBillet do
4
4
  before(:each) do
5
- @billet = Cobregratis::Billet.new
5
+ @billet = Cobregratis::BankBillet.new
6
6
  end
7
7
 
8
8
  it "should be instance of Cobregratis::Base" do
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,12 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
3
4
  require 'cobregratis'
4
- require 'spec'
5
- require 'spec/autorun'
6
5
 
7
- Spec::Runner.configure do |config|
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
8
11
 
9
12
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cobregratis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 1
9
- - 0
10
- version: 0.1.0
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rafael Lima
@@ -15,29 +15,106 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-22 00:00:00 -03:00
18
+ date: 2011-03-27 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rspec
23
22
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ type: :runtime
24
+ name: activeresource
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ">="
28
29
  - !ruby/object:Gem::Version
29
- hash: 13
30
+ hash: 1
30
31
  segments:
32
+ - 2
33
+ - 1
34
+ version: "2.1"
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ prerelease: false
38
+ type: :runtime
39
+ name: activesupport
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 2
31
48
  - 1
49
+ version: "2.1"
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ prerelease: false
53
+ type: :development
54
+ name: rspec
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
32
62
  - 2
33
- - 9
34
- version: 1.2.9
63
+ - 3
64
+ - 0
65
+ version: 2.3.0
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ prerelease: false
35
69
  type: :development
36
- version_requirements: *id001
70
+ name: bundler
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 23
77
+ segments:
78
+ - 1
79
+ - 0
80
+ - 0
81
+ version: 1.0.0
82
+ requirement: *id004
37
83
  - !ruby/object:Gem::Dependency
38
- name: activeresource
39
84
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
85
+ type: :development
86
+ name: jeweler
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ~>
91
+ - !ruby/object:Gem::Version
92
+ hash: 7
93
+ segments:
94
+ - 1
95
+ - 5
96
+ - 2
97
+ version: 1.5.2
98
+ requirement: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ prerelease: false
101
+ type: :development
102
+ name: rcov
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ requirement: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ prerelease: false
115
+ type: :runtime
116
+ name: activeresource
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
41
118
  none: false
42
119
  requirements:
43
120
  - - ">="
@@ -47,12 +124,12 @@ dependencies:
47
124
  - 2
48
125
  - 1
49
126
  version: "2.1"
50
- type: :runtime
51
- version_requirements: *id002
127
+ requirement: *id007
52
128
  - !ruby/object:Gem::Dependency
53
- name: activesupport
54
129
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
130
+ type: :runtime
131
+ name: activesupport
132
+ version_requirements: &id008 !ruby/object:Gem::Requirement
56
133
  none: false
57
134
  requirements:
58
135
  - - ">="
@@ -62,15 +139,30 @@ dependencies:
62
139
  - 2
63
140
  - 1
64
141
  version: "2.1"
65
- type: :runtime
66
- version_requirements: *id003
142
+ requirement: *id008
143
+ - !ruby/object:Gem::Dependency
144
+ prerelease: false
145
+ type: :development
146
+ name: rspec
147
+ version_requirements: &id009 !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 2
155
+ - 3
156
+ - 0
157
+ version: 2.3.0
158
+ requirement: *id009
67
159
  description: "\n\
68
160
  Cobre Gr\xC3\xA1tis\n\n\
69
161
  Configure by adding the following:\n\n\
70
162
  require 'cobregratis'\n\
71
163
  Cobregratis::Base.site = 'https://app.cobregratis.com.br/'\n\
72
164
  Cobregratis::Base.user = 'your_api_username'\n\
73
- Cobregratis::Base.user = 'your_api_password'\n "
165
+ Cobregratis::Base.user = 'your_api_password'\n "
74
166
  email: contato@rafael.adm.br
75
167
  executables: []
76
168
 
@@ -80,8 +172,10 @@ extra_rdoc_files:
80
172
  - LICENSE
81
173
  - README.mkdn
82
174
  files:
175
+ - .bundle/config
83
176
  - .document
84
- - .gitignore
177
+ - Gemfile
178
+ - Gemfile.lock
85
179
  - LICENSE
86
180
  - README.mkdn
87
181
  - Rakefile
@@ -92,20 +186,20 @@ files:
92
186
  - init.rb
93
187
  - lib/cachable.rb
94
188
  - lib/cobregratis.rb
189
+ - lib/cobregratis/bank_billet.rb
95
190
  - lib/cobregratis/base.rb
96
- - lib/cobregratis/billet.rb
97
191
  - spec/cachable_spec.rb
192
+ - spec/cobregratis/bank_billet_spec.rb
98
193
  - spec/cobregratis/base_spec.rb
99
- - spec/cobregratis/billet_spec.rb
100
194
  - spec/spec.opts
101
195
  - spec/spec_helper.rb
102
196
  has_rdoc: true
103
197
  homepage: http://github.com/rafaelp/cobregratis
104
- licenses: []
105
-
198
+ licenses:
199
+ - MIT
106
200
  post_install_message:
107
- rdoc_options:
108
- - --charset=UTF-8
201
+ rdoc_options: []
202
+
109
203
  require_paths:
110
204
  - lib
111
205
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -134,9 +228,9 @@ signing_key:
134
228
  specification_version: 3
135
229
  summary: "Ruby Wrapper around Cobre Gr\xC3\xA1tis API"
136
230
  test_files:
231
+ - examples/config_initializers_cobregratis.rb
232
+ - examples/sample.rb
137
233
  - spec/cachable_spec.rb
234
+ - spec/cobregratis/bank_billet_spec.rb
138
235
  - spec/cobregratis/base_spec.rb
139
- - spec/cobregratis/billet_spec.rb
140
236
  - spec/spec_helper.rb
141
- - examples/config_initializers_cobregratis.rb
142
- - examples/sample.rb
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- cobregratis.gemspec
@@ -1,4 +0,0 @@
1
- module Cobregratis
2
- class Billet < Base
3
- end
4
- end