rubyidescat 0.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: 05f8e4732bc8763f258891d85ac85b728a3183bf
4
+ data.tar.gz: b874249990b868818d811e7df22d6cdda740b174
5
+ SHA512:
6
+ metadata.gz: 9522bb426c8ee377f229f19b7e36a768fb117903efb1e5e97991b0e48b9af6a34b897204e9f883384b4bad48e65ca148165d52d93276b7a672de05a6bbf372eb
7
+ data.tar.gz: 7248d2fa3158e23a09def5dfe04bad244a5cb52067b81cf7bf8bfc525f51410f72e88a11744f898785c7845492cef68053d336ff0c0cb10d88ebb16118230373
@@ -0,0 +1,18 @@
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
+ spec/fixtures
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubyidescat.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joan Roig
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.
@@ -0,0 +1,30 @@
1
+ # Rubyidescat
2
+
3
+ TODO: Write a gem description
4
+ test
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'rubyidescat'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install rubyidescat
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,7 @@
1
+ require "rubyidescat/version"
2
+ require 'rubyidescat/client'
3
+
4
+ module Rubyidescat
5
+ require "httparty"
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,33 @@
1
+ module Rubyidescat
2
+ class Client
3
+ BASE_URL = 'http://api.idescat.cat/'
4
+
5
+ def request_url
6
+ URI.escape(@request_url)
7
+ end
8
+
9
+ def initialize(attributes = {})
10
+ attributes.each do |attr, value|
11
+ self.send("#{attr}=", value)
12
+ end
13
+ end
14
+
15
+ def poblacio(version, format, operation, params = {})
16
+ @format = format
17
+ @version = version
18
+ @operation = operation
19
+ @params = params
20
+ @request_url = BASE_URL + 'pob/' + @version + '/' + @operation + '.' + @format
21
+ @request_url += '?p=' + @params.map{|k,v|"#{k}/#{[v].flatten.join(",")}"}.join(";") unless @params.empty?
22
+ make_call
23
+ end
24
+
25
+ private
26
+
27
+ def make_call
28
+ response = HTTParty.get self.request_url
29
+ return JSON.parse response.body
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Rubyidescat
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubyidescat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubyidescat"
8
+ spec.version = Rubyidescat::VERSION
9
+ spec.authors = ["Joan Roig Arderiu"]
10
+ spec.email = ["roigarderiu@gmail.com"]
11
+ spec.description = %q{Wrapper for the Idescat API}
12
+ spec.summary = %q{Wrapper for the Idescat API}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_dependency "httparty"
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubyidescat do
4
+ it 'should have a version' do
5
+ Rubyidescat::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Rubyidescat::Client do
5
+ describe 'initialize' do
6
+ it 'creates a new client' do
7
+ expect { Rubyidescat::Client.new }.to_not raise_error
8
+ end
9
+
10
+ it 'should have a base url for the API' do
11
+ #expect { Rubyidescat::Client }.to be_const_defined :BASE_URL
12
+ end
13
+ end
14
+
15
+ let(:client) { Rubyidescat::Client.new }
16
+ describe 'poblacio' do
17
+
18
+ describe 'sug' do
19
+ it 'should set format correctly' do
20
+ VCR.use_cassette('empty sug') do
21
+ client.poblacio('v1','json','sug')
22
+ expect(client.instance_variable_get('@format')).to eq('json')
23
+ end
24
+ end
25
+
26
+ it 'should set version correctly' do
27
+ VCR.use_cassette('empty sug') do
28
+ client.poblacio('v1','json','sug')
29
+ expect(client.instance_variable_get('@version')).to eq('v1')
30
+ end
31
+ end
32
+
33
+ it 'should set operation correctly' do
34
+ VCR.use_cassette('empty sug') do
35
+ client.poblacio('v1','json','sug')
36
+ expect(client.instance_variable_get('@operation')).to eq('sug')
37
+ end
38
+ end
39
+
40
+ it 'should set request url correctly' do
41
+ VCR.use_cassette('torrelles sug') do
42
+ results = client.poblacio('v1','json','sug', { 'q' => 'torrelles' })
43
+ expect(client.request_url).to eq('http://api.idescat.cat/pob/v1/sug.json?p=q/torrelles')
44
+ end
45
+ end
46
+
47
+ it 'should accept one parameter and return results' do
48
+ VCR.use_cassette('torrelles sug') do
49
+ results = client.poblacio('v1','json','sug', { 'q' => 'torrelles' })
50
+ expect(results).to eq(["torrelles",["Torrelles de Foix","Torrelles de Llobregat"]])
51
+ end
52
+ end
53
+
54
+ it 'should accept several extra parameters and return results' do
55
+ VCR.use_cassette('sug tipus com "barc"') do
56
+ results = client.poblacio('v1','json','sug', { 'q' => 'barc', 'tipus' => 'com' })
57
+ expect(results).to eq(["barc",["Barcelonès"]])
58
+ end
59
+ end
60
+
61
+ it 'should accept multiple parameters with multiple values and return results' do
62
+ VCR.use_cassette('sug multiple parameters and values') do
63
+ results = client.poblacio('v1','json','sug', { 'q' => 'ab', 'tipus' => ['mun','np'] })
64
+ expect(results).to eq(["ab",["Abella","Abella de la Conca","Abella, l'","Abrera"]])
65
+ end
66
+ end
67
+ end
68
+
69
+ describe 'cerca' do
70
+ it 'should set operation correctly' do
71
+ VCR.use_cassette('empty sug') do
72
+ client.poblacio('v1','json','cerca')
73
+ expect(client.instance_variable_get('@operation')).to eq('cerca')
74
+ end
75
+ end
76
+
77
+ it 'should set request url correctly' do
78
+ VCR.use_cassette('torrelles cerca') do
79
+ results = client.poblacio('v1','json','cerca', { 'q' => 'torrelles' })
80
+ expect(client.request_url).to eq('http://api.idescat.cat/pob/v1/cerca.json?p=q/torrelles')
81
+ end
82
+ end
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubyidescat'
2
+ require 'vcr'
3
+ require 'support/vcr'
@@ -0,0 +1,4 @@
1
+ VCR.configure do |c|
2
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
3
+ c.hook_into :webmock
4
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyidescat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joan Roig Arderiu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Wrapper for the Idescat API
98
+ email:
99
+ - roigarderiu@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/rubyidescat.rb
110
+ - lib/rubyidescat/client.rb
111
+ - lib/rubyidescat/version.rb
112
+ - rubyidescat.gemspec
113
+ - spec/base_spec.rb
114
+ - spec/client_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/support/vcr.rb
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.1.9
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Wrapper for the Idescat API
141
+ test_files:
142
+ - spec/base_spec.rb
143
+ - spec/client_spec.rb
144
+ - spec/spec_helper.rb
145
+ - spec/support/vcr.rb