sitra_client 0.0.1

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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sitra_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 jeanbaptistevilain
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,29 @@
1
+ # SitraClient
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sitra_client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sitra_client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.verbose = true
6
+ t.pattern = '**/*_test.rb'
7
+ end
@@ -0,0 +1,11 @@
1
+ module AttributeHelper
2
+ def attributes=(hash)
3
+ hash.each do |key, value|
4
+ instance_variable_set("@#{key}", value)
5
+ end
6
+ end
7
+
8
+ def attributes
9
+ Hash[instance_variables.map { |name| [name.to_s[1..-1], instance_variable_get(name)] }]
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'sitra_client/attribute_helper'
2
+ require 'json'
3
+
4
+ class SitraQuery
5
+
6
+ include AttributeHelper
7
+
8
+ def initialize(api_key, site_identifier, criteria = {})
9
+ @apiKey = api_key
10
+ @siteWebExportIdV1 = site_identifier
11
+ self.attributes = criteria
12
+ end
13
+
14
+ def to_params
15
+ JSON.generate attributes
16
+ end
17
+
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'sitra_client/attribute_helper'
2
+ require 'json'
3
+
4
+ class SitraResponse
5
+
6
+ include AttributeHelper
7
+
8
+ def initialize
9
+ @json_response = ''
10
+ end
11
+
12
+ def append_line(line)
13
+ @json_response += line unless line.nil?
14
+ end
15
+
16
+ def as_hash
17
+ JSON.parse @json_response, :symbolize_names => true
18
+ end
19
+
20
+ def as_raw_json
21
+ @json_response
22
+ end
23
+
24
+ end
@@ -0,0 +1,3 @@
1
+ module SitraClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'sitra_client/version'
2
+ require 'sitra_client/sitra_query'
3
+ require 'sitra_client/sitra_response'
4
+ require 'open-uri'
5
+
6
+ module SitraClient
7
+
8
+ # Configuration defaults
9
+ @config = {
10
+ :base_url => 'http://api.sitra-tourisme.com/api/v001',
11
+ :api_key => '',
12
+ :site_identifier => ''
13
+ }
14
+
15
+ @valid_config_keys = @config.keys
16
+ @logger = Logger.new(STDOUT)
17
+
18
+ # Configure through hash
19
+ def self.configure(opts = {})
20
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
21
+ end
22
+
23
+ def self.config
24
+ @config
25
+ end
26
+
27
+ def self.query(criteria = {})
28
+ response = SitraResponse.new
29
+ query = SitraQuery.new(@config[:api_key], @config[:site_identifier], criteria)
30
+ @logger.info "Search query : #{@config[:base_url]}/recherche/list-objets-touristiques?query=#{query.to_params}"
31
+ open("#{@config[:base_url]}/recherche/list-objets-touristiques?query=#{CGI.escape query.to_params}") { |f|
32
+ f.each_line {|line| response.append_line(line)}
33
+ }
34
+ response
35
+ end
36
+
37
+ 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 'sitra_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sitra_client"
8
+ spec.version = SitraClient::VERSION
9
+ spec.authors = ["jeanbaptistevilain"]
10
+ spec.email = ["jbvilain@gmail.com"]
11
+ spec.description = %q{Sitra Client Gem}
12
+ spec.summary = %q{A simple Ruby wrapper for the SITRA JSON 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.0"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency "shoulda"
25
+ spec.add_runtime_dependency "rails", "~> 3.2.14"
26
+ spec.add_runtime_dependency "json"
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ gem 'shoulda'
3
+ require 'test/unit'
4
+ require 'shoulda'
5
+ require 'sitra_client/sitra_query'
6
+
7
+ class SitraQueryTest < Test::Unit::TestCase
8
+
9
+ should 'populate query with parameters' do
10
+
11
+ query = SitraQuery.new('dummy_key', 'dummy_identifier', {:first_key => 'first_value', :second_key => 'second_value'})
12
+
13
+ assert_equal '{"apiKey":"dummy_key","siteWebExportIdV1":"dummy_identifier","first_key":"first_value","second_key":"second_value"}', query.to_params
14
+ end
15
+
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ gem 'shoulda'
3
+ require 'test/unit'
4
+ require 'shoulda'
5
+ require 'sitra_client/sitra_response'
6
+
7
+
8
+ class SitraResponseTest < Test::Unit::TestCase
9
+
10
+ setup do
11
+ @response = '{"apiKey":"dummy_key","siteWebExportIdV1":"dummy_identifier","first_key":"first_value","second_key":"second_value"}'
12
+ end
13
+
14
+ should 'store raw json response' do
15
+
16
+ sitra_response = SitraResponse.new
17
+ sitra_response.append_line(@response)
18
+
19
+ assert_equal @response, sitra_response.as_raw_json
20
+
21
+ end
22
+
23
+ should 'return response as hash' do
24
+
25
+ sitra_response = SitraResponse.new
26
+ sitra_response.append_line(@response)
27
+
28
+ response_hash = sitra_response.as_hash
29
+
30
+ assert_equal 'dummy_key', response_hash[:apiKey]
31
+ assert_equal 'dummy_identifier', response_hash[:siteWebExportIdV1]
32
+ assert_equal 'first_value', response_hash[:first_key]
33
+ assert_equal 'second_value', response_hash[:second_key]
34
+
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitra_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jeanbaptistevilain
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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: test-unit
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
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: shoulda
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
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: rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 3.2.14
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 3.2.14
94
+ - !ruby/object:Gem::Dependency
95
+ name: json
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
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
+ description: Sitra Client Gem
111
+ email:
112
+ - jbvilain@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE.txt
120
+ - README.md
121
+ - Rakefile
122
+ - lib/sitra_client.rb
123
+ - lib/sitra_client/attribute_helper.rb
124
+ - lib/sitra_client/sitra_query.rb
125
+ - lib/sitra_client/sitra_response.rb
126
+ - lib/sitra_client/version.rb
127
+ - sitra_client.gemspec
128
+ - test/sitra_client/sitra_query_test.rb
129
+ - test/sitra_client/sitra_response_test.rb
130
+ homepage: ''
131
+ licenses:
132
+ - MIT
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 1.8.24
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: A simple Ruby wrapper for the SITRA JSON api
155
+ test_files:
156
+ - test/sitra_client/sitra_query_test.rb
157
+ - test/sitra_client/sitra_response_test.rb