ean3 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,45 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ .DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ *.swp
43
+
44
+ test/config.rb
45
+
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'faraday', "~> 0.7.5"
4
+ gem 'faraday_middleware', '>= 0.6', '< 0.8'
5
+ gem 'hashie', '~> 1.0'
6
+ gem 'log4r'
7
+
8
+ group :development do
9
+ gem "shoulda"
10
+ gem "jeweler", "~> 1.5"
11
+ gem "rcov"
12
+ gem "fakeweb", "~> 1.3"
13
+ gem "jnunemaker-matchy", "~> 0.4"
14
+ gem "json_pure", "~> 1.4"
15
+ gem "multi_json", ">= 0.0.5", "< 2.0.0"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.6)
5
+ fakeweb (1.3.0)
6
+ faraday (0.7.5)
7
+ addressable (~> 2.2.6)
8
+ multipart-post (~> 1.1.3)
9
+ rack (>= 1.1.0, < 2)
10
+ faraday_middleware (0.7.0)
11
+ faraday (~> 0.7.3)
12
+ git (1.2.5)
13
+ hashie (1.2.0)
14
+ jeweler (1.6.4)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ jnunemaker-matchy (0.4.0)
19
+ json_pure (1.6.4)
20
+ log4r (1.1.10)
21
+ multi_json (1.0.4)
22
+ multipart-post (1.1.3)
23
+ rack (1.3.6)
24
+ rake (0.9.2.2)
25
+ rcov (0.9.11)
26
+ shoulda (2.11.3)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ fakeweb (~> 1.3)
33
+ faraday (~> 0.7.5)
34
+ faraday_middleware (>= 0.6, < 0.8)
35
+ hashie (~> 1.0)
36
+ jeweler (~> 1.5)
37
+ jnunemaker-matchy (~> 0.4)
38
+ json_pure (~> 1.4)
39
+ log4r
40
+ multi_json (>= 0.0.5, < 2.0.0)
41
+ rcov
42
+ shoulda
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.mkd ADDED
@@ -0,0 +1,34 @@
1
+ ## Ean
2
+
3
+ ean of rails plugin.
4
+
5
+ http://developer.ean.com/docs/read/hotels/Version_3
6
+
7
+ # Example
8
+
9
+ ## console
10
+
11
+ gem install ean3
12
+
13
+ ## Gemfile
14
+
15
+ require 'ean3'
16
+
17
+ ## controller
18
+
19
+ options = {
20
+ :apikey => 'XXXXXXXXX',
21
+ :secret => 'XXXXXXXXX',
22
+ :minorRev => 12,
23
+ :locale => "ja_JP",
24
+ :currencyCode => "JPY",
25
+ :debug => true
26
+ }
27
+ @client = Ean3::Client.new(options)
28
+ @response = @client.getList({
29
+ :arrivalDate => "02/10/2012",
30
+ :city => "tokyo"
31
+ })
32
+
33
+
34
+ Copyright (c) 2012 [name of plugin creator], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env rake
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ require 'bundler'
6
+ begin
7
+ Bundler.setup :default, :development
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts 'Run `bundle install` to install missing gem'
11
+ exit e.status_code
12
+ end
13
+
14
+ desc 'Default: run unit tests.'
15
+ task :default => :test
16
+
17
+ desc 'Test the ean plugin.'
18
+ Rake::TestTask.new(:test) do |t|
19
+ t.libs << 'lib'
20
+ t.libs << 'test'
21
+ t.pattern = 'test/**/*_test.rb'
22
+ t.verbose = true
23
+ end
24
+
25
+ desc 'Generate documentation for the ean plugin.'
26
+ RDoc::Task.new(:rdoc) do |rdoc|
27
+ rdoc.rdoc_dir = 'rdoc'
28
+ rdoc.title = 'Ean'
29
+ rdoc.options << '--line-numbers' << '--inline-source'
30
+ rdoc.rdoc_files.include('README')
31
+ rdoc.rdoc_files.include('lib/**/*.rb')
32
+ end
33
+
data/ean3-0.0.1.gem ADDED
Binary file
data/ean3-0.0.2.gem ADDED
Binary file
data/ean3.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ean3'
3
+ s.version = '0.0.4'
4
+ s.date = '2012-01-29'
5
+ s.summary = "ean of plugin"
6
+ s.description = "http://developer.ean.com/docs/read/hotels/Version_3"
7
+ s.authors = ["Toshiaki Takahashi"]
8
+ s.email = 'toshipon123@gmail.com'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.homepage = 'http://rubygems.org/gems/ean3'
11
+ s.add_dependency('faraday', '~> 0.7.5')
12
+ s.add_dependency('faraday_middleware', '>= 0.6', '< 0.8')
13
+ s.add_dependency('hashie', '~> 1.0')
14
+ s.add_dependency('log4r')
15
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require 'lib/ean'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
data/lib/ean3.rb ADDED
@@ -0,0 +1,17 @@
1
+ # Ean
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+
6
+ directory = File.expand_path(File.dirname(__FILE__))
7
+
8
+ module Ean3
9
+ class << self
10
+
11
+ end
12
+
13
+ require 'ean3/hotels'
14
+ require 'ean3/client'
15
+ #require 'ean3/car_rentals'
16
+ #require 'ean3/air'
17
+ end
@@ -0,0 +1,20 @@
1
+ module Ean333
2
+ class APIError < StandardError
3
+
4
+ attr_reader :code
5
+ attr_reader :detail
6
+ attr_reader :type
7
+ attr_reader :response
8
+
9
+ def initialize(error, response)
10
+ @code = error.code
11
+ @details = error.errorDetail
12
+ @type = error.errorType
13
+ @response = response
14
+ end
15
+
16
+ def message
17
+ "#{@type}: #{@detail} (#{@code})"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module Ean3
2
+ module CarRentals
3
+ end
4
+ end
@@ -0,0 +1,96 @@
1
+ module Ean3
2
+ class Client
3
+ extend Forwardable
4
+
5
+ include Hotels
6
+
7
+ attr_reader :cid, :apikey, :secret
8
+
9
+ def initialize options={}
10
+ @cid = options[:cid].nil? ? default_cid : options[:cid]
11
+ @apikey = options[:apikey]
12
+ @secret = options[:secret]
13
+ @minorRev = options[:minorRev]
14
+ @locale = options[:locale]
15
+ @currencyCode = options[:currencyCode]
16
+ @customerSessionId = options[:customerSessionId]
17
+ @customerIpAddress = options[:customerIpAddress]
18
+ @customerUserAgent = options[:customerUserAgent]
19
+ @debug = options[:debug]
20
+ #@sig =
21
+ @ssl = options[:ssl]
22
+ end
23
+
24
+ def api_version
25
+ 'v3'
26
+ end
27
+
28
+ def api_url
29
+ version = api_version()
30
+ if @ssl
31
+ "https://book.api.ean.com/ean-services/rs/hotel/#{version}/"
32
+ else
33
+ "http://api.ean.com/ean-services/rs/hotel/#{version}/"
34
+ end
35
+ end
36
+
37
+ def default_cid
38
+ '55505'
39
+ end
40
+
41
+ def ssl
42
+ @ssl
43
+ end
44
+
45
+ def sig
46
+ # apikey + secret + timestamp -> md5 key
47
+ ''
48
+ end
49
+
50
+ def connection
51
+ params = {}
52
+ params[:cid] = @cid
53
+ params[:apikey] = @apikey
54
+ params[:secret] = @secret
55
+ params[:minorRev] = @minorRev
56
+ params[:locale] = @locale
57
+ params[:currencyCode] = @currencyCode
58
+ params[:customerSessionId] = @customerSessionId
59
+ params[:customerIpAddress] = @customerIpAddress
60
+ params[:customerUserAgent] = @customerUserAgent
61
+ @connection ||= Faraday::Connection.new(:url => api_url, :ssl => @ssl, :sig => sig, :params => params, :headers => default_headers) do |builder|
62
+ builder.use Faraday::Request::Multipart
63
+ builder.use Faraday::Request::UrlEncoded
64
+
65
+ if @debug
66
+ builder.use Faraday::Response::Logger
67
+ end
68
+
69
+ builder.use Faraday::Response::Mashify
70
+ builder.use Faraday::Response::ParseJson
71
+
72
+ builder.adapter Faraday.default_adapter
73
+
74
+ builder.request :multipart
75
+ builder.request :url_encoded
76
+ builder.request :json
77
+ end
78
+ end
79
+
80
+ def return_error_or_body(response, response_body)
81
+ if response.success?
82
+ response_body
83
+ else
84
+ raise Ean::APIError.new(response.headers, response.body)
85
+ end
86
+ end
87
+
88
+ private
89
+ def default_headers
90
+ headers = {
91
+ :accept => 'application/json',
92
+ :user_agent => 'Ruby gem'
93
+ }
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,61 @@
1
+ module Ean3
2
+ module Hotels
3
+ # Request a List of Hotels
4
+ #
5
+ # @param [Hash] options
6
+ #
7
+ # = HotelListRequest Bese Elements =
8
+ # @option options String :arrivalDate - The desired check-in date
9
+ # - Format MM/DD/YYYY
10
+ # - Example 10/18/2011
11
+ # @option options String :departureDate - The desired check-out date
12
+ # @option options int :numberOfResults
13
+ #
14
+ # = Location search parameters alternative #1 (use city/stateProvinceCode/countryCode parameters) =
15
+ # @option options String :city
16
+ # @option options String :stateProvinceCode
17
+ # @option options String :countryCode
18
+ #
19
+ def getList(options={})
20
+ response = connection.get do |req|
21
+ req.url "list", options
22
+ end
23
+ return_error_or_body(response, response.body)
24
+ end
25
+
26
+ def getGeoLocation
27
+ response = connection.get("geoSearch")
28
+ return_error_or_body(response, response.body.response)
29
+ end
30
+
31
+ def getInformation
32
+ response = conncetion.get("info")
33
+ return_error_or_body(response, response.body.response)
34
+ end
35
+
36
+ def getAvaliabillity
37
+ end
38
+
39
+ def getRules
40
+ end
41
+
42
+ def getPaymentInfo
43
+ end
44
+
45
+ def getReservation
46
+ end
47
+
48
+ def getAlternateProperties
49
+ end
50
+
51
+ def getItinerary
52
+ end
53
+
54
+ def getCancel
55
+ end
56
+
57
+ def getPing
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+
5
+ context 'test samplet methos' do
6
+ should "hogehoge" do
7
+ true
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class TestHotelGetList < Test::Unit::TestCase
4
+
5
+ context "When using the ean API and working with hotels getList" do
6
+ setup do
7
+ @client = ean_test_client
8
+ end
9
+
10
+ should "hoge" do
11
+ stub_get("http://api.ean.com/ean-service/rs/hotel/v3/list", "hotel_getlist.json")
12
+ options = {
13
+ :arrivalDate => "02/10/2012",
14
+ #:departureDate => "02/10/2012",
15
+ :city => "tokyo"
16
+ };
17
+ hotels = @client.getList(options);
18
+ #logger.debug hotels
19
+ #puts hotels
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,69 @@
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
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+ require 'fakeweb'
13
+ require 'json'
14
+ require 'hashie'
15
+
16
+ #require 'log4r'
17
+ #require 'log4r/configurator'
18
+
19
+ #formatter = Log4r::PatternFormatter.new(
20
+ # :pattern => "%d %C [%l]: %M",
21
+ # :date_format => "%Y/%m/%d %H:%M:%S"
22
+ #)
23
+ #outputter = Log4r::StdoutOutputter.new(STDOUT, :formatter => formatter)
24
+ #logger = Log4r::Logger.new("ean")
25
+ #logger.add(outputter)
26
+ #config.logger = logger
27
+
28
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
29
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
30
+ require 'ean3'
31
+ require 'config'
32
+
33
+ FakeWeb.allow_net_connect = true
34
+
35
+ def ean_test_client
36
+ options = {}
37
+ options[:apikey] = APIKEY # from config.rb
38
+ options[:secret] = SECRET
39
+ options[:minorRev] = 12
40
+ options[:debug] = true
41
+ options[:locale] = "ja_JP"
42
+ options[:currencyCode] = "JPY"
43
+ Ean3::Client.new(options)
44
+ end
45
+
46
+ def ean_url(url)
47
+ url =~ /^http/ ? url : "http://api.ean.com/ean-services/rs/hotel/v3/#{url}"
48
+ end
49
+
50
+ def fixture_file(filename, options={})
51
+ return '' if filename == ''
52
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
53
+ fixture = File.read(file_path)
54
+
55
+ case File.extname(file_path)
56
+ when '.json'
57
+ options[:parse] ? Hashie::Mash.new(JSON.parse(fixture)) : fixture
58
+ else
59
+ fixture
60
+ end
61
+ end
62
+
63
+ def stub_get(url, filename, options={})
64
+ opts = {
65
+ :body => fixture_file(filename),
66
+ :content_type => 'application/json; charset=utf-8'
67
+ }.merge(options)
68
+ FakeWeb.register_uri(:get, ean_url(url), opts)
69
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ean3
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 4
9
+ version: 0.0.4
10
+ platform: ruby
11
+ authors:
12
+ - Toshiaki Takahashi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-29 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: faraday
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 7
30
+ - 5
31
+ version: 0.7.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: faraday_middleware
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 6
44
+ version: "0.6"
45
+ - - <
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ - 8
50
+ version: "0.8"
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: hashie
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 1
62
+ - 0
63
+ version: "1.0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: log4r
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :runtime
77
+ version_requirements: *id004
78
+ description: http://developer.ean.com/docs/read/hotels/Version_3
79
+ email: toshipon123@gmail.com
80
+ executables: []
81
+
82
+ extensions: []
83
+
84
+ extra_rdoc_files: []
85
+
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - MIT-LICENSE
91
+ - README.mkd
92
+ - Rakefile
93
+ - ean3-0.0.1.gem
94
+ - ean3-0.0.2.gem
95
+ - ean3.gemspec
96
+ - init.rb
97
+ - install.rb
98
+ - lib/ean3.rb
99
+ - lib/ean3/api_error.rb
100
+ - lib/ean3/car_rentals.rb
101
+ - lib/ean3/client.rb
102
+ - lib/ean3/hotels.rb
103
+ - test/client_test.rb
104
+ - test/config.rb
105
+ - test/fixtures/hotel_getlist.json
106
+ - test/hotels_getlist_test.rb
107
+ - test/test_helper.rb
108
+ - uninstall.rb
109
+ has_rdoc: true
110
+ homepage: http://rubygems.org/gems/ean3
111
+ licenses: []
112
+
113
+ post_install_message:
114
+ rdoc_options: []
115
+
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ requirements: []
133
+
134
+ rubyforge_project:
135
+ rubygems_version: 1.3.6
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: ean of plugin
139
+ test_files: []
140
+