cic 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cic.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'webmock', git: 'git@github.com:kurenn/webmock.git'
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Abraham Kuri Vargas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # CIC Ruby Gem
2
+
3
+ cic-rb is a client which communicates with the CIC API, and interact
4
+ with it
5
+
6
+ It was developed for usage in Ruby on Rails web applications, but it
7
+ also works as a standalone library
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'cic'
14
+
15
+ Living on the edge
16
+
17
+ gem 'cic', git: 'git@github.com:IcaliaLabs/cic-rb.git'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install cic
26
+
27
+ Request for reports
28
+ ---
29
+
30
+ ```ruby
31
+ Cic::Report.all
32
+ ```
33
+ It will output:
34
+ ```ruby
35
+ #<Cic::Report:0x007fb0a0874f58
36
+ @attributes=
37
+ {"ticket"=>"#7LZA",
38
+ "content"=>
39
+ "ACCIDENTE* en Vasconcelos lateral para tomar el t\u00FAnel SP #mtyfollow 16:26 v\u00EDa @Monitores_SPGG cc @SanPedroen72",
40
+ "state"=>"read",
41
+ "created_at"=>"2013-02-21T16:29:30-06:00",
42
+ "updated_at"=>"2013-02-21T16:34:15-06:00",
43
+ "lat"=>"25.65419634916782",
44
+ "lng"=>"-100.33913254737848",
45
+ "is_public"=>true,
46
+ "votes"=>0,
47
+ "stars"=>0.0,
48
+ "address_detail"=>{...},
49
+ "group"=>"Vialidad y Transito (SS)",
50
+ "categories"=>["ACCIDENTE"]},
51
+ @raw_attributes=
52
+ {"ticket"=>"#7LZA",
53
+ "content"=>
54
+ "ACCIDENTE* en Vasconcelos lateral para tomar el t\u00FAnel SP #mtyfollow 16:26 v\u00EDa @Monitores_SPGG cc @SanPedroen72",
55
+ "state"=>"read",
56
+ "created_at"=>"2013-02-21T16:29:30-06:00",
57
+ "updated_at"=>"2013-02-21T16:34:15-06:00",
58
+ "lat"=>"25.65419634916782",
59
+ "lng"=>"-100.33913254737848",
60
+ "is_public"=>true,
61
+ "votes"=>0,
62
+ "stars"=>0.0,
63
+ "address_detail"=>
64
+ {"formatted_address"=>
65
+ "Jos\u00E9 Vasconcelos 419, Residencial San Agust\u00EDn 1er Sector, 66260 San Pedro Garza Garc\u00EDa, Nuevo Le\u00F3n, Mexico",
66
+ "zipcode"=>"66260",
67
+ "county"=>
68
+ {"long_name"=>"San Pedro Garza Garc\u00EDa",
69
+ "short_name"=>"San Pedro Garza Garc\u00EDa"},
70
+ "state"=>{"long_name"=>"Nuevo Leon", "short_name"=>"NL"},
71
+ "neighborhood"=>
72
+ {"long_name"=>"Residencial San Agust\u00EDn 1er Sector",
73
+ "short_name"=>"Residencial San Agust\u00EDn 1er Sector"}},
74
+ "group"=>"Vialidad y Transito (SS)",
75
+ "categories"=>["ACCIDENTE"]}>
76
+ ```
77
+
78
+ We have a where clause to embrace em all!
79
+
80
+ ```ruby
81
+ Cic::Report.where(for_group: 142)
82
+ ```
83
+
84
+ Heads up!, the params you can send are, for_group, for_category, limit, until
85
+
86
+ It will have the same output as above.
87
+
88
+ Request for categories
89
+ ---
90
+
91
+ ```ruby
92
+ Cic::Category.all
93
+ ```
94
+ It will output:
95
+
96
+ ```ruby
97
+ #<Cic::Category:0x007fb0a28e2d58
98
+ @attributes=
99
+ {"id"=>420,
100
+ "name"=>"AVISOS",
101
+ "metadata"=>false,
102
+ "type"=>"blackbox",
103
+ "group"=>["Comunidad"]},
104
+ @raw_attributes=
105
+ {"id"=>420,
106
+ "name"=>"AVISOS",
107
+ "metadata"=>false,
108
+ "type"=>"blackbox",
109
+ "group"=>["Comunidad"]}>,
110
+ #<Cic::Category:0x007fb0a28e2bf0
111
+ @attributes=
112
+ {"id"=>412,
113
+ "name"=>"BACHE O VIA DA\u00D1ADA",
114
+ "metadata"=>false,
115
+ "type"=>"blackbox",
116
+ "group"=>["Servicios Publicos (CS)"]},
117
+ @raw_attributes=
118
+ {"id"=>412,
119
+ "name"=>"BACHE O VIA DA\u00D1ADA",
120
+ "metadata"=>false,
121
+ "type"=>"blackbox",
122
+ "group"=>["Servicios Publicos (CS)"]}>
123
+ ```
124
+
125
+ Request for groups
126
+ ---
127
+ ```ruby
128
+ Cic::Group.all
129
+ ```
130
+ It will output:
131
+
132
+ ```ruby
133
+ #<Cic::Group:0x007fb0a1c1b610
134
+ @attributes=
135
+ {"id"=>142, "name"=>"Asesorias Generales", "categories"=>[["OTROS", 424]]},
136
+ @raw_attributes=
137
+ {"id"=>142, "name"=>"Asesorias Generales", "categories"=>[["OTROS", 424]]}>,
138
+ #<Cic::Group:0x007fb0a1c1b4f8
139
+ @attributes=
140
+ {"id"=>258, "name"=>"CFE", "categories"=>[["FALTA ELECTRICIDAD", 423]]},
141
+ @raw_attributes=
142
+ {"id"=>258, "name"=>"CFE", "categories"=>[["FALTA ELECTRICIDAD", 423]]}>,
143
+ ```
144
+
145
+ ## Hashie that out!
146
+
147
+ Thanks to Hashie library you can access the report attributes by the key value and/or chaining them
148
+
149
+ ```ruby
150
+ report = Cic::Report.find('#Y1UI')
151
+
152
+ report.ticket
153
+ #=> '#Y1UI'
154
+
155
+ category = Cic::Category.all.first
156
+ category.name
157
+ #=> "AVISOS"
158
+
159
+ group = Cic::Group.all.first
160
+ group.name
161
+ #=> "Asesorias Generales"
162
+ ```
163
+
164
+ ## Contributing
165
+
166
+ 1. Fork it
167
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
168
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
169
+ 4. Push to the branch (`git push origin my-new-feature`)
170
+ 5. Create new Pull Request
171
+
172
+ ## Changelog
173
+ <ul>
174
+ <li>Current gem version 1.0.0</li>
175
+ <li>Previous gem version 0.0.1</li>
176
+ <li>Add post method to create reports</li>
177
+ <li>Refactor for code reuse</li>
178
+ <li>GET requests for all entities</li>
179
+ </ul>
180
+
181
+
182
+ ## Devs
183
+ <ul>
184
+ <li>Abraham Kuri Vargas (@kurenn)</li>
185
+ </ul>
186
+
187
+ ## Future
188
+ <ul>
189
+ <li>Add post method to create reports</li>
190
+ </ul>
191
+
192
+
193
+ ## Credits
194
+ Icalia Labs - weare@icalialabs.com
195
+
196
+ [Follow us](http://twitter.com/icalialabs "Follow us")
197
+
198
+
199
+ [Like us on Facebook](https://www.facebook.com/icalialab "Like us on Facebook")
200
+
201
+ ## License
202
+ Copyright (c) 2011 Icalia Labs
203
+
204
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
205
+
206
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
207
+
208
+ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/gpl.html.
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
data/cic.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ #$: << 'lib'
5
+
6
+ require 'cic/version'
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = "cic"
10
+ gem.version = Cic::VERSION
11
+ gem.authors = ["Abraham Kuri Vargas"]
12
+ gem.email = ["kurenn@icalialabs.com"]
13
+ gem.description = %q{Communicates the CIC API}
14
+ gem.summary = %q{CIC Api Integration}
15
+ gem.homepage = ""
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.name = 'cic'
19
+ gem.version = Cic::VERSION
20
+ gem.platform = Gem::Platform::RUBY
21
+ gem.rubyforge_project = 'cic'
22
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = ["lib"]
25
+
26
+ gem.add_dependency "httparty"
27
+ gem.add_dependency "hashie"
28
+ gem.add_dependency "activesupport"
29
+ gem.add_dependency "json"
30
+ gem.add_development_dependency 'rspec'
31
+ gem.add_development_dependency 'debugger'
32
+ gem.add_development_dependency 'shoulda-matchers'
33
+ gem.test_files = Dir.glob("{spec}/**/*.rb")
34
+ end
data/lib/cic.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "cic/version"
2
+
3
+ module Cic
4
+ end
@@ -0,0 +1,49 @@
1
+ require 'hashie'
2
+ require 'httparty'
3
+ require 'cic/errors'
4
+ require 'active_support/inflector'
5
+
6
+ module ActiveCic
7
+ class Base
8
+ attr_accessor :attributes
9
+ attr_reader :raw_attributes
10
+
11
+ BASE_URL = "api.nl.cic.mx/0/nl"
12
+
13
+ include HTTParty
14
+
15
+ base_uri BASE_URL
16
+
17
+ def initialize(hash)
18
+ self.attributes = Hashie::Mash.new(hash)
19
+ @raw_attributes = hash
20
+ end
21
+
22
+ def method_missing(name, *args)
23
+ self.attributes.send(name, args)
24
+ rescue NoMethodError
25
+ super
26
+ end
27
+
28
+ def self.all
29
+ class_name = self.pluralize_child_class_name
30
+ response = self.get("/#{class_name}.json")
31
+ if response.success?
32
+ response.parsed_response[class_name].map { |hash| self.new(hash) }
33
+ else
34
+ raise_exception(response.code, response.body)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def self.raise_exception(code, body)
41
+ raise Cic::Exception::ServerError.new(code, body) if code >= 500
42
+ raise Cic::Exception::ClientError.new(code, body) if code < 500
43
+ end
44
+
45
+ def self.pluralize_child_class_name
46
+ self.to_s.split('::').last.downcase.pluralize
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,18 @@
1
+ $: << 'lib'
2
+ require 'cic/active_cic'
3
+
4
+ module Cic
5
+ class Category < ActiveCic::Base
6
+
7
+ def initialize(hash)
8
+ super(hash)
9
+ end
10
+
11
+ #Fields reserved from Hashie override
12
+ %w(id type).each do |attr|
13
+ define_method attr do
14
+ self.attributes.send(attr)
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/cic/errors.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Cic
2
+ class CicError < StandardError; end
3
+
4
+ module Exception
5
+
6
+ class APIError < ::Cic::CicError
7
+ attr_accessor :http_status, :response_body
8
+
9
+ def initialize(http_status, response_body, error_info = nil)
10
+ message = " [HTTP #{http_status}] #{response_body}"
11
+ super(message)
12
+ end
13
+ end
14
+
15
+ # Any error with a 5xx HTTP status code
16
+ class ServerError < APIError; end
17
+
18
+ # Any error with a 4xx HTTP status code
19
+ class ClientError < APIError; end
20
+ end
21
+ end
data/lib/cic/group.rb ADDED
@@ -0,0 +1,15 @@
1
+ $: << 'lib'
2
+ require 'cic/active_cic'
3
+
4
+ module Cic
5
+ class Group < ActiveCic::Base
6
+
7
+ def initialize(hash)
8
+ super(hash)
9
+ end
10
+
11
+ def id
12
+ self.attributes.id
13
+ end
14
+ end
15
+ end
data/lib/cic/report.rb ADDED
@@ -0,0 +1,35 @@
1
+ $: << 'lib'
2
+ require 'cic/active_cic'
3
+
4
+ module Cic
5
+ class Report < ActiveCic::Base
6
+
7
+ def initialize(hash)
8
+ super(hash)
9
+ end
10
+
11
+ def self.find(ticket)
12
+ response = self.get("/reports.json")
13
+ if response.success?
14
+ report_hash = response.parsed_response["reports"].select { |report| report['ticket'] == ticket }.first
15
+ report_hash ? self.new(report_hash) : nil
16
+ else
17
+ raise_exception(response.code, response.body)
18
+ end
19
+ end
20
+
21
+ def save
22
+ self.class.post("/reports.json", body: self.raw_attributes )
23
+ true #POST always finds its way...
24
+ end
25
+
26
+ def self.where(params = {})
27
+ response = self.get("/reports.json", query: params)
28
+ if response.success?
29
+ response.parsed_response['reports'].map { |report_hash| self.new(report_hash) }
30
+ else
31
+ raise_exception(response.code, response.body)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Cic
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+ require 'cic/category'
3
+ require 'cic/errors'
4
+ require 'helper'
5
+
6
+ describe Cic::Category do
7
+
8
+ URL = "http://api.nl.cic.mx/0/nl/categories.json"
9
+
10
+ before(:each) do
11
+ @attr = {
12
+ "id" => 407,
13
+ "name" => "ACCIDENTE",
14
+ "metadata" => false,
15
+ "type" => "blackbox",
16
+ "group" => ["Servicios Publicos (CS)"]
17
+ }
18
+ end
19
+
20
+ subject { Cic::Category.new(@attr) }
21
+ let(:category) { Cic::Category.new(@attr) }
22
+
23
+ it { should respond_to(:attributes) }
24
+ it { should respond_to(:id) }
25
+ it { should respond_to(:type) }
26
+ it { should respond_to(:raw_attributes) }
27
+
28
+ describe '#all' do
29
+
30
+ context 'when response is success' do
31
+ it 'returns an empty array when no reports' do
32
+ mock_request(URL, { categories: [] })
33
+ Cic::Category.all.should be_empty
34
+ end
35
+
36
+ it 'returns an array of reports' do
37
+ mock_request(URL, { categories: [@attr] })
38
+ Cic::Category.all.first.should be_instance_of(Cic::Category)
39
+ end
40
+ end
41
+
42
+
43
+ context 'when response fails' do
44
+ it 'raises a server exception' do
45
+ stub_request(:get, URL).to_return(status: 500)
46
+ lambda { Cic::Category.all }.should raise_exception(Cic::Exception::ServerError)
47
+ end
48
+
49
+ it 'raises a client exception' do
50
+ stub_request(:get, URL).to_return(status: 404)
51
+ lambda { Cic::Category.all }.should raise_exception(Cic::Exception::ClientError)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#id' do
57
+ it 'returns the id from the category' do
58
+ category.id.should eql 407
59
+ end
60
+ end
61
+
62
+ describe '#type' do
63
+ it 'returns the type from the category' do
64
+ category.type.should eql "blackbox"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'cic/group'
3
+ require 'cic/errors'
4
+ require 'helper'
5
+
6
+ describe Cic::Group do
7
+
8
+ URL = "http://api.nl.cic.mx/0/nl/groups.json"
9
+
10
+ before(:each) do
11
+ @attr = {
12
+ "id" => 142,
13
+ "name" => "Asesorias Generales",
14
+ "categories" => [
15
+ "FALTA ELECTRICIDAD",
16
+ 424
17
+ ]
18
+ }
19
+ end
20
+
21
+ subject { Cic::Group.new(@attr) }
22
+ let(:group) { Cic::Group.new(@attr) }
23
+
24
+ it { should respond_to(:attributes) }
25
+ it { should respond_to(:raw_attributes) }
26
+ it { should respond_to(:id) }
27
+
28
+ describe '#all' do
29
+
30
+ context 'when response is success' do
31
+ it 'returns an empty array when no groups' do
32
+ mock_request(URL, { groups: [] })
33
+ Cic::Group.all.should be_empty
34
+ end
35
+
36
+ it 'returns an array of groups' do
37
+ mock_request(URL, { groups: [@attr] })
38
+ Cic::Group.all.first.should be_instance_of(Cic::Group)
39
+ end
40
+ end
41
+
42
+
43
+ context 'when response fails' do
44
+ it 'raises a server exception' do
45
+ stub_request(:get, URL).to_return(status: 500)
46
+ lambda { Cic::Group.all }.should raise_exception(Cic::Exception::ServerError)
47
+ end
48
+
49
+ it 'raises a client exception' do
50
+ stub_request(:get, URL).to_return(status: 404)
51
+ lambda { Cic::Group.all }.should raise_exception(Cic::Exception::ClientError)
52
+ end
53
+ end
54
+ end
55
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ def mock_request(url, body, params = {}, method = :get)
4
+ stub = stub_request(method, url)
5
+ stub = stub.with(query: params) unless params.length.zero?
6
+ stub = stub.to_return(headers: { "Content-Type" => 'application/json' }, body: body.to_json)
7
+ stub
8
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+ require 'cic/report'
3
+ require 'cic/errors'
4
+ require 'helper'
5
+
6
+ describe Cic::Report do
7
+
8
+ URL = "http://api.nl.cic.mx/0/nl/reports.json"
9
+
10
+ before(:each) do
11
+ @attr = {"ticket"=>"#7LVB", "content"=>"*ACCIDENTE* En Carretera a Laredo y Jos\u00E9 Clemente Orozco ESC #mtyfollow 11:32 via @escuadronvial", "state"=>"read", "created_at"=>"2013-02-20T11:33:37-06:00", "updated_at"=>"2013-02-20T11:35:20-06:00", "lat"=>"25.79174804389648", "lng"=>"-100.28132557868958", "is_public"=>true, "votes"=>0, "stars"=>0.0, "address_detail"=>{"formatted_address"=>"Jose Clemente Orozco, Sin Nombre de Colonia 17, General Escobedo, NL, M\u00E9xico", "zipcode"=>nil, "county"=>{"long_name"=>"General Escobedo", "short_name"=>"Gral Escobedo"}, "state"=>{"long_name"=>"Nuevo Le\u00F3n", "short_name"=>"NL"}, "neighborhood"=>{"long_name"=>"Sin Nombre de Colonia 17", "short_name"=>"Sin Nombre de Col 17"}}, "group"=>"Vialidad y Transito (SS)", "categories"=>["ACCIDENTE"]}
12
+ end
13
+
14
+ subject { Cic::Report.new(@attr) }
15
+ let(:report) { Cic::Report.new(@attr) }
16
+
17
+ it { should respond_to(:attributes) }
18
+ it { should respond_to(:raw_attributes) }
19
+
20
+ describe '#find' do
21
+
22
+ context 'when response is success' do
23
+ it 'returns the record specified by the ticket id' do
24
+ mock_request(URL, { reports: [@attr] })
25
+ Cic::Report.find(@attr['ticket']).ticket.should eql @attr['ticket']
26
+ end
27
+
28
+ it 'returns nil when no record found' do
29
+ mock_request(URL, { reports: [@attr] })
30
+ Cic::Report.find('#1234').should be_nil
31
+ end
32
+ end
33
+
34
+ context 'when response fails' do
35
+ it 'raises a server exception' do
36
+ stub_request(:get, URL).to_return(status: 500)
37
+ lambda { Cic::Report.find('#1234')}.should raise_exception(Cic::Exception::ServerError)
38
+ end
39
+
40
+ it 'raises a client exception' do
41
+ stub_request(:get, URL).to_return(status: 404)
42
+ lambda { Cic::Report.find('#1234') }.should raise_exception(Cic::Exception::ClientError)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#all' do
48
+
49
+ context 'when response is success' do
50
+ it 'returns an empty array when no reports' do
51
+ mock_request(URL, { reports: [] })
52
+ Cic::Report.all.should be_empty
53
+ end
54
+
55
+ it 'returns an array of reports' do
56
+ mock_request(URL, { reports: [@attr] })
57
+ Cic::Report.all.first.should be_instance_of(Cic::Report)
58
+ end
59
+ end
60
+
61
+
62
+ context 'when response fails' do
63
+ it 'raises a server exception' do
64
+ stub_request(:get, URL).to_return(status: 500)
65
+ lambda { Cic::Report.all }.should raise_exception(Cic::Exception::ServerError)
66
+ end
67
+
68
+ it 'raises a client exception' do
69
+ stub_request(:get, URL).to_return(status: 404)
70
+ lambda { Cic::Report.all }.should raise_exception(Cic::Exception::ClientError)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#where' do
76
+ it 'returns reports by group id' do
77
+ options = { for_group: 142 }
78
+ mock_request(URL, { reports: [@attr, @attr] }, options)
79
+ Cic::Report.where(options).should_not be_empty
80
+ end
81
+
82
+ it 'returns reports by category id' do
83
+ options = { for_category: 142 }
84
+ mock_request(URL, { reports: [@attr, @attr] }, options)
85
+ Cic::Report.where(options).should_not be_empty
86
+ end
87
+
88
+ it 'returns reports by until date' do
89
+ options = { :until => "2012-01-01" }
90
+ mock_request(URL, { reports: [@attr, @attr] }, options)
91
+ Cic::Report.where(:until => "2012-01-01").should_not be_empty #YYYY-MM-DD
92
+ end
93
+
94
+ it 'returns reports by group id and category id' do
95
+ options = { for_category: 417, for_group: 134 }
96
+ mock_request(URL, { reports: [@attr, @attr] }, options)
97
+ Cic::Report.where(options).should_not be_empty
98
+ end
99
+ end
100
+
101
+ describe '#save' do
102
+ before(:each) do
103
+ @params = {
104
+ content: 'Prueba Kuri jalo',
105
+ address: 'cataluna 206',
106
+ origin: 'mailto:jsmith@example.com',
107
+ return_path: 'mailto:jsmith@example.com',
108
+ lat: '25.67316978132684',
109
+ lng: '-100.35339117050171',
110
+ address: 'cataluna 206',
111
+ assets: 'http://icalialabs.com/img/logo.png'
112
+ }
113
+ end
114
+ it 'returns true if report was saved successfully' do
115
+ report = Cic::Report.new(@params)
116
+ report.save.should be_true
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,28 @@
1
+ require 'webmock/rspec'
2
+ require 'json'
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+ #config.color_enabled = true
16
+ config.formatter = 'documentation'
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ config.order = 'random'
23
+
24
+ config.before(:each) do
25
+ WebMock.reset!
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cic
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Abraham Kuri Vargas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hashie
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: debugger
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: shoulda-matchers
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Communicates the CIC API
127
+ email:
128
+ - kurenn@icalialabs.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - cic.gemspec
140
+ - lib/cic.rb
141
+ - lib/cic/active_cic.rb
142
+ - lib/cic/category.rb
143
+ - lib/cic/errors.rb
144
+ - lib/cic/group.rb
145
+ - lib/cic/report.rb
146
+ - lib/cic/version.rb
147
+ - spec/category_spec.rb
148
+ - spec/group_spec.rb
149
+ - spec/helper.rb
150
+ - spec/report_spec.rb
151
+ - spec/spec_helper.rb
152
+ homepage: ''
153
+ licenses: []
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project: cic
172
+ rubygems_version: 1.8.24
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: CIC Api Integration
176
+ test_files:
177
+ - spec/category_spec.rb
178
+ - spec/group_spec.rb
179
+ - spec/helper.rb
180
+ - spec/report_spec.rb
181
+ - spec/spec_helper.rb