cic 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d466605f47ae0bcf9f2cde32ca07f62f4706f6d0
4
+ data.tar.gz: 05acd6a25ab04814a30d2585b7ab5a43b28ba9b7
5
+ SHA512:
6
+ metadata.gz: 5afd868a6aa51c9d09020f930aede35ca8c3aea7d938c1920b5e9fbb845a0b7fe362b2dc0fcaac7069c07cf26a2febffb0ced53c47ca753da1006fca7654eb5e
7
+ data.tar.gz: e73808dc30e391e6b25e97e0237a208b3f50abb4fa0615f457074d80d3aeb0854ae6bb0654c6c19abb6a014d6d7f9ca1256e9676e7fe65c11b0d6c4edd11113a
@@ -8,11 +8,12 @@ require 'cic/version'
8
8
  Gem::Specification.new do |gem|
9
9
  gem.name = "cic"
10
10
  gem.version = Cic::VERSION
11
- gem.authors = ["Abraham Kuri Vargas"]
12
- gem.email = ["kurenn@icalialabs.com"]
11
+ gem.authors = ["Abraham Kuri Vargas", "Alicia Catalina"]
12
+ gem.email = ["kurenn@icalialabs.com", "alicia@icalialabs.com"]
13
13
  gem.description = %q{Communicates the CIC API}
14
14
  gem.summary = %q{CIC Api Integration}
15
- gem.homepage = ""
15
+ gem.homepage = "https://github.com/IcaliaLabs/cic-rb"
16
+ gem.licenses = ["MIT"]
16
17
 
17
18
  gem.files = `git ls-files`.split($/)
18
19
  gem.name = 'cic'
@@ -23,12 +24,12 @@ Gem::Specification.new do |gem|
23
24
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
25
  gem.require_paths = ["lib"]
25
26
 
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'
27
+ gem.add_dependency "httparty", '~> 0'
28
+ gem.add_dependency "hashie", '~> 0'
29
+ gem.add_dependency "activesupport", '~> 0'
30
+ gem.add_dependency "json", '~> 0'
31
+ gem.add_development_dependency 'rspec', '~> 0'
32
+ gem.add_development_dependency 'pry-byebug', '~> 0'
33
+ gem.add_development_dependency 'shoulda-matchers', '~> 0'
33
34
  gem.test_files = Dir.glob("{spec}/**/*.rb")
34
35
  end
@@ -3,30 +3,36 @@ require 'cic/active_cic'
3
3
 
4
4
  module Cic
5
5
  class Report < ActiveCic::Base
6
+ attr_reader :ticket_id
6
7
 
7
8
  def initialize(hash)
8
- super(hash)
9
+ super(hash)
9
10
  end
10
11
 
11
12
  def self.find(ticket)
12
- response = self.get("/reports.json")
13
+ response = self.get("/reports.json")
13
14
  if response.success?
14
- report_hash = response.parsed_response["reports"].select { |report| report['ticket'] == ticket }.first
15
+ report_hash = response.parsed_response["reports"].select { |report| report['ticket'] == ticket }.first
15
16
  report_hash ? self.new(report_hash) : nil
16
17
  else
17
18
  raise_exception(response.code, response.body)
18
19
  end
19
20
  end
20
21
 
21
- def save
22
- self.class.post("/reports.json", body: self.raw_attributes )
23
- true #POST always finds its way...
22
+ def save
23
+ response = self.class.post("/reports.json", body: self.raw_attributes )
24
+ if response.success?
25
+ @ticket_id = response.parsed_response["reports"]["ticket"]
26
+ true #POST always finds its way...
27
+ else
28
+ false
29
+ end
24
30
  end
25
31
 
26
32
  def self.where(params = {})
27
- response = self.get("/reports.json", query: params)
33
+ response = self.get("/reports.json", query: params)
28
34
  if response.success?
29
- response.parsed_response['reports'].map { |report_hash| self.new(report_hash) }
35
+ response.parsed_response['reports'].map { |report_hash| self.new(report_hash) }
30
36
  else
31
37
  raise_exception(response.code, response.body)
32
38
  end
@@ -1,3 +1,3 @@
1
1
  module Cic
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -2,13 +2,23 @@ require 'spec_helper'
2
2
  require 'cic/report'
3
3
  require 'cic/errors'
4
4
  require 'helper'
5
+ require 'active_support/core_ext/object/to_query'
5
6
 
6
7
  describe Cic::Report do
7
8
 
8
9
  URL = "http://api.nl.cic.mx/0/nl/reports.json"
9
10
 
10
11
  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
+ @attr = { "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" => {
13
+ "formatted_address" => "Jose Clemente Orozco, Sin Nombre de Colonia 17, General Escobedo, NL, M\u00E9xico", "zipcode" => nil, "county" => {
14
+ "long_name" => "General Escobedo", "short_name" => "Gral Escobedo"
15
+ }, "state" => {
16
+ "long_name" => "Nuevo Le\u00F3n", "short_name" => "NL"
17
+ }, "neighborhood" => {
18
+ "long_name" => "Sin Nombre de Colonia 17", "short_name" => "Sin Nombre de Col 17"
19
+ }
20
+ }, "group" => "Vialidad y Transito (SS)", "categories" => ["ACCIDENTE"]
21
+ }
12
22
  end
13
23
 
14
24
  subject { Cic::Report.new(@attr) }
@@ -19,14 +29,17 @@ describe Cic::Report do
19
29
 
20
30
  describe '#find' do
21
31
 
32
+ before(:each) do
33
+ @find_attr = @attr.merge({ "ticket" => "#A2S3" })
34
+ end
22
35
  context 'when response is success' do
23
36
  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']
37
+ mock_request(URL, { reports: [@find_attr] })
38
+ Cic::Report.find(@find_attr['ticket']).ticket.should eql @find_attr['ticket']
26
39
  end
27
40
 
28
41
  it 'returns nil when no record found' do
29
- mock_request(URL, { reports: [@attr] })
42
+ mock_request(URL, { reports: [@find_attr] })
30
43
  Cic::Report.find('#1234').should be_nil
31
44
  end
32
45
  end
@@ -101,19 +114,23 @@ describe Cic::Report do
101
114
  describe '#save' do
102
115
  before(:each) do
103
116
  @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'
117
+ content: 'Lorem'
112
118
  }
119
+ @report = Cic::Report.new(@attr)
120
+ stub_request(:post, "http://api.nl.cic.mx/0/nl/reports.json").
121
+ with(:body => "content=*ACCIDENTE*%20En%20Carretera%20a%20Laredo%20y%20Jos%C3%A9%20Clemente%20Orozco%20ESC%20%23mtyfollow%2011%3A32%20via%20%40escuadronvial&state=read&created_at=2013-02-20T11%3A33%3A37-06%3A00&updated_at=2013-02-20T11%3A35%3A20-06%3A00&lat=25.79174804389648&lng=-100.28132557868958&is_public=true&votes=0&stars=0.0&address_detail[formatted_address]=Jose%20Clemente%20Orozco%2C%20Sin%20Nombre%20de%20Colonia%2017%2C%20General%20Escobedo%2C%20NL%2C%20M%C3%A9xico&address_detail[zipcode]=&address_detail[county][long_name]=General%20Escobedo&address_detail[county][short_name]=Gral%20Escobedo&address_detail[state][long_name]=Nuevo%20Le%C3%B3n&address_detail[state][short_name]=NL&address_detail[neighborhood][long_name]=Sin%20Nombre%20de%20Colonia%2017&address_detail[neighborhood][short_name]=Sin%20Nombre%20de%20Col%2017&group=Vialidad%20y%20Transito%20(SS)&categories[]=ACCIDENTE",
122
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
123
+ to_return(:status => 200, :body => {reports: { ticket: "#123" }}.to_json, :headers => {"Content-Type" => 'application/json'})
113
124
  end
125
+
114
126
  it 'returns true if report was saved successfully' do
115
- report = Cic::Report.new(@params)
116
- report.save.should be_true
127
+ expect(report.save).to eql(true)
128
+ end
129
+
130
+ it 'returns a ticket number on the response' do
131
+ expect{ @report.save }.to change{ @report.ticket_id }.from(nil).to("#123")
117
132
  end
133
+
134
+
118
135
  end
119
136
  end
@@ -1,5 +1,6 @@
1
1
  require 'webmock/rspec'
2
2
  require 'json'
3
+ require 'pry-byebug'
3
4
  # This file was generated by the `rspec --init` command. Conventionally, all
4
5
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
6
  # Require this file using `require "spec_helper"` to ensure that it is only
metadata CHANGED
@@ -1,137 +1,124 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Abraham Kuri Vargas
8
+ - Alicia Catalina
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2014-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>='
18
+ - - "~>"
20
19
  - !ruby/object:Gem::Version
21
20
  version: '0'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ! '>='
25
+ - - "~>"
28
26
  - !ruby/object:Gem::Version
29
27
  version: '0'
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: hashie
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ! '>='
32
+ - - "~>"
36
33
  - !ruby/object:Gem::Version
37
34
  version: '0'
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ! '>='
39
+ - - "~>"
44
40
  - !ruby/object:Gem::Version
45
41
  version: '0'
46
42
  - !ruby/object:Gem::Dependency
47
43
  name: activesupport
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - "~>"
52
47
  - !ruby/object:Gem::Version
53
48
  version: '0'
54
49
  type: :runtime
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
- - - ! '>='
53
+ - - "~>"
60
54
  - !ruby/object:Gem::Version
61
55
  version: '0'
62
56
  - !ruby/object:Gem::Dependency
63
57
  name: json
64
58
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
59
  requirements:
67
- - - ! '>='
60
+ - - "~>"
68
61
  - !ruby/object:Gem::Version
69
62
  version: '0'
70
63
  type: :runtime
71
64
  prerelease: false
72
65
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
66
  requirements:
75
- - - ! '>='
67
+ - - "~>"
76
68
  - !ruby/object:Gem::Version
77
69
  version: '0'
78
70
  - !ruby/object:Gem::Dependency
79
71
  name: rspec
80
72
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
73
  requirements:
83
- - - ! '>='
74
+ - - "~>"
84
75
  - !ruby/object:Gem::Version
85
76
  version: '0'
86
77
  type: :development
87
78
  prerelease: false
88
79
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
80
  requirements:
91
- - - ! '>='
81
+ - - "~>"
92
82
  - !ruby/object:Gem::Version
93
83
  version: '0'
94
84
  - !ruby/object:Gem::Dependency
95
- name: debugger
85
+ name: pry-byebug
96
86
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
87
  requirements:
99
- - - ! '>='
88
+ - - "~>"
100
89
  - !ruby/object:Gem::Version
101
90
  version: '0'
102
91
  type: :development
103
92
  prerelease: false
104
93
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
94
  requirements:
107
- - - ! '>='
95
+ - - "~>"
108
96
  - !ruby/object:Gem::Version
109
97
  version: '0'
110
98
  - !ruby/object:Gem::Dependency
111
99
  name: shoulda-matchers
112
100
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
101
  requirements:
115
- - - ! '>='
102
+ - - "~>"
116
103
  - !ruby/object:Gem::Version
117
104
  version: '0'
118
105
  type: :development
119
106
  prerelease: false
120
107
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
108
  requirements:
123
- - - ! '>='
109
+ - - "~>"
124
110
  - !ruby/object:Gem::Version
125
111
  version: '0'
126
112
  description: Communicates the CIC API
127
113
  email:
128
114
  - kurenn@icalialabs.com
115
+ - alicia@icalialabs.com
129
116
  executables: []
130
117
  extensions: []
131
118
  extra_rdoc_files: []
132
119
  files:
133
- - .gitignore
134
- - .rspec
120
+ - ".gitignore"
121
+ - ".rspec"
135
122
  - Gemfile
136
123
  - LICENSE.txt
137
124
  - README.md
@@ -149,29 +136,29 @@ files:
149
136
  - spec/helper.rb
150
137
  - spec/report_spec.rb
151
138
  - spec/spec_helper.rb
152
- homepage: ''
153
- licenses: []
139
+ homepage: https://github.com/IcaliaLabs/cic-rb
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
154
143
  post_install_message:
155
144
  rdoc_options: []
156
145
  require_paths:
157
146
  - lib
158
147
  required_ruby_version: !ruby/object:Gem::Requirement
159
- none: false
160
148
  requirements:
161
- - - ! '>='
149
+ - - ">="
162
150
  - !ruby/object:Gem::Version
163
151
  version: '0'
164
152
  required_rubygems_version: !ruby/object:Gem::Requirement
165
- none: false
166
153
  requirements:
167
- - - ! '>='
154
+ - - ">="
168
155
  - !ruby/object:Gem::Version
169
156
  version: '0'
170
157
  requirements: []
171
158
  rubyforge_project: cic
172
- rubygems_version: 1.8.24
159
+ rubygems_version: 2.4.2
173
160
  signing_key:
174
- specification_version: 3
161
+ specification_version: 4
175
162
  summary: CIC Api Integration
176
163
  test_files:
177
164
  - spec/category_spec.rb
@@ -179,3 +166,4 @@ test_files:
179
166
  - spec/helper.rb
180
167
  - spec/report_spec.rb
181
168
  - spec/spec_helper.rb
169
+ has_rdoc: