getyourguide 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rvmrc +53 -0
- data/.rvmrc.01.29.2015-18:48:37 +53 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/getyourguide.gemspec +25 -0
- data/lib/getyourguide.rb +18 -0
- data/lib/getyourguide/api_client.rb +100 -0
- data/lib/getyourguide/errors/api_error.rb +11 -0
- data/lib/getyourguide/models/activity.rb +19 -0
- data/lib/getyourguide/models/category.rb +12 -0
- data/lib/getyourguide/models/destination.rb +16 -0
- data/lib/getyourguide/models/image_format.rb +14 -0
- data/lib/getyourguide/models/location.rb +14 -0
- data/lib/getyourguide/models/top_category.rb +15 -0
- data/lib/getyourguide/parsers/categories.rb +28 -0
- data/lib/getyourguide/parsers/default.rb +66 -0
- data/lib/getyourguide/parsers/destinations.rb +35 -0
- data/lib/getyourguide/parsers/image_formats.rb +30 -0
- data/lib/getyourguide/parsers/products.rb +35 -0
- data/lib/getyourguide/parsers/top_categories.rb +31 -0
- data/lib/getyourguide/version.rb +3 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 19307fe44acbf6f58e872f7e1fb79b3e5236d7d9
|
4
|
+
data.tar.gz: 8224fb8205137f411a3ed2173626696301e4f657
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0c67f4741fac95c39686a5cfd711cc6981724d70a8af0dd5ef2f0c1b156ee45b6a23054e960d899fc50205af0d6afc451766e717f60cdaf38b561fb5aaa267b
|
7
|
+
data.tar.gz: 7ad17bb76296d86058aa0072357fb9b7e4e436f3d4081eebc39c07d61057cb4d86f04e0bdc30f66a1fe09fd23fe2ee993ef6759883a4b5ec2821ff758355a923
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 2.1.4@getyourguide" > .rvmrc
|
9
|
+
environment_id="ruby-2.1.4@getyourguide"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.25.33 (stable)" # 1.10.1 seems like a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
+
do
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
+
then \. "${__hook}" || true
|
30
|
+
fi
|
31
|
+
done
|
32
|
+
unset __hook
|
33
|
+
if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
|
34
|
+
then
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
|
37
|
+
" # show the user the ruby and gemset they are using in green
|
38
|
+
else printf "%b" "Using: $GEM_HOME
|
39
|
+
" # don't use colors in non-interactive shells
|
40
|
+
fi
|
41
|
+
fi
|
42
|
+
else
|
43
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
44
|
+
rvm --create use "$environment_id" || {
|
45
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
46
|
+
return 1
|
47
|
+
}
|
48
|
+
fi
|
49
|
+
|
50
|
+
# If you use bundler, this might be useful to you:
|
51
|
+
# if [[ -s Gemfile ]] && {
|
52
|
+
# ! builtin command -v bundle >/dev/null ||
|
53
|
+
# builtin command -v bundle | GREP_OPTIONS=""
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 2.1.4@getyourguide" > .rvmrc
|
9
|
+
environment_id="ruby-2.1.4@getyourguide"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.25.33 (stable)" # 1.10.1 seems like a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
+
do
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
+
then \. "${__hook}" || true
|
30
|
+
fi
|
31
|
+
done
|
32
|
+
unset __hook
|
33
|
+
if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
|
34
|
+
then
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
|
37
|
+
" # show the user the ruby and gemset they are using in green
|
38
|
+
else printf "%b" "Using: $GEM_HOME
|
39
|
+
" # don't use colors in non-interactive shells
|
40
|
+
fi
|
41
|
+
fi
|
42
|
+
else
|
43
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
44
|
+
rvm --create use "$environment_id" || {
|
45
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
46
|
+
return 1
|
47
|
+
}
|
48
|
+
fi
|
49
|
+
|
50
|
+
# If you use bundler, this might be useful to you:
|
51
|
+
# if [[ -s Gemfile ]] && {
|
52
|
+
# ! builtin command -v bundle >/dev/null ||
|
53
|
+
# builtin command -v bundle | GREP_OPTIONS=""
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rémi Delhaye
|
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,48 @@
|
|
1
|
+
![GetYourGuide logo](http://www.creative-city-berlin.de/uploads/institutions/getyourguide_deutschland_gmbh/avatar/20120202120023.png)
|
2
|
+
|
3
|
+
Read the [gem's wiki](https://github.com/Libertrip/getyourguide/wiki) for more features!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'getyourguide'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install getyourguide
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
# I. The easy way
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'getyourguide'
|
27
|
+
|
28
|
+
# required
|
29
|
+
partner_id = 'XXXXXXXXXX'
|
30
|
+
options = {
|
31
|
+
:q => 'product_list',
|
32
|
+
:where => 'Rome'
|
33
|
+
}
|
34
|
+
|
35
|
+
# optional (default is set to EN)
|
36
|
+
language = 'fr'
|
37
|
+
|
38
|
+
api = GetYourGuide::ApiClient.new(partner_id, language)
|
39
|
+
parsed_activities = api.call_and_parse(options)
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( [https://github.com/Libertrip/getyourguide/fork](https://github.com/Libertrip/getyourguide/fork) )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'GetYourGuide/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "getyourguide"
|
8
|
+
spec.version = GetYourGuide::VERSION
|
9
|
+
spec.authors = ['Rémi Delhaye', 'Libertrip']
|
10
|
+
spec.email = ['remi@libertrip.com', 'maxime@libertrip.com']
|
11
|
+
spec.summary = 'A simple ruby on rails client for GetYourGuide partner XML API'
|
12
|
+
spec.description = 'A simple ruby client for GetYourGuide partner XML API'
|
13
|
+
spec.homepage = 'https://github.com/Libertrip/getyourguide'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.5', '>= 1.5.0'
|
24
|
+
spec.add_runtime_dependency 'httpclient', '~> 2.3', '>= 2.3.1'
|
25
|
+
end
|
data/lib/getyourguide.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
end
|
3
|
+
|
4
|
+
require "GetYourGuide/version"
|
5
|
+
require "GetYourGuide/api_client"
|
6
|
+
require "GetYourGuide/errors/api_error"
|
7
|
+
require "GetYourGuide/models/activity"
|
8
|
+
require "GetYourGuide/models/category"
|
9
|
+
require "GetYourGuide/models/destination"
|
10
|
+
require "GetYourGuide/models/image_format"
|
11
|
+
require "GetYourGuide/models/location"
|
12
|
+
require "GetYourGuide/models/top_category"
|
13
|
+
require "GetYourGuide/parsers/default"
|
14
|
+
require "GetYourGuide/parsers/categories"
|
15
|
+
require "GetYourGuide/parsers/destinations"
|
16
|
+
require "GetYourGuide/parsers/image_formats"
|
17
|
+
require "GetYourGuide/parsers/products"
|
18
|
+
require "GetYourGuide/parsers/top_categories"
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class ApiClient
|
6
|
+
def initialize(partner_id, forced_language = nil)
|
7
|
+
@partner_id = partner_id
|
8
|
+
if forced_language.nil?
|
9
|
+
@forced_language = 'en'
|
10
|
+
else
|
11
|
+
@forced_language = forced_language
|
12
|
+
end
|
13
|
+
@base_request_url = construct_base_url
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(options)
|
17
|
+
@options = options
|
18
|
+
|
19
|
+
xml = Nokogiri::XML(open(construct_formated_url)) do |config|
|
20
|
+
config.nonet
|
21
|
+
config.noblanks
|
22
|
+
end
|
23
|
+
|
24
|
+
xml.remove_namespaces!
|
25
|
+
|
26
|
+
return_xml_or_raise_error xml
|
27
|
+
end
|
28
|
+
|
29
|
+
def call_and_parse(options)
|
30
|
+
api_xml = call options
|
31
|
+
product_parser = get_good_parser.new(api_xml)
|
32
|
+
product_parser.process
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def construct_base_url
|
38
|
+
"#{api_base_url}?#{get_language_string}&#{get_partner_id_string}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def construct_formated_url
|
42
|
+
request_url = @base_request_url
|
43
|
+
|
44
|
+
@options.keys.each do |key|
|
45
|
+
request_url += "&#{key}=#{@options[key]}"
|
46
|
+
end
|
47
|
+
|
48
|
+
request_url
|
49
|
+
end
|
50
|
+
|
51
|
+
def return_xml_or_raise_error(xml)
|
52
|
+
if xml.xpath('.//errors').size > 0
|
53
|
+
raise Errors::ApiError.new, xml.xpath('.//error').inner_text
|
54
|
+
else
|
55
|
+
xml
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_good_parser
|
60
|
+
if available_query_list.include? @options[:q]
|
61
|
+
case @options[:q]
|
62
|
+
when 'product_list'
|
63
|
+
GetYourGuide::Parsers::Products
|
64
|
+
when 'destination_list'
|
65
|
+
GetYourGuide::Parsers::Destinations
|
66
|
+
when 'image_format_list'
|
67
|
+
GetYourGuide::Parsers::ImageFormats
|
68
|
+
when 'category_list'
|
69
|
+
GetYourGuide::Parsers::Categories
|
70
|
+
when 'top_categories'
|
71
|
+
GetYourGuide::Parsers::TopCategories
|
72
|
+
end
|
73
|
+
else
|
74
|
+
raise Errors::ApiError.new, "Your :q key (#{@options[:q]}:#{@options[:q].class}) doesnt match with an available query."
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def available_query_list
|
79
|
+
[
|
80
|
+
'product_list',
|
81
|
+
'destination_list',
|
82
|
+
'image_format_list',
|
83
|
+
'category_list',
|
84
|
+
'top_categories'
|
85
|
+
]
|
86
|
+
end
|
87
|
+
|
88
|
+
def api_base_url
|
89
|
+
'https://api.getyourguide.com/'
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_partner_id_string
|
93
|
+
"partner_id=#{@partner_id}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_language_string
|
97
|
+
"language=#{@forced_language.to_s}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Models
|
3
|
+
class Activity
|
4
|
+
attr_accessor :provider_id, :title, :abstract, :categories, :destinations, :starting_point, :indivative_price, :rating, :pictures
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@provider_id = attributes[:provider_id]
|
8
|
+
@title = attributes[:title]
|
9
|
+
@abstract = attributes[:abstract]
|
10
|
+
@categories = attributes[:categories]
|
11
|
+
@destinations = attributes[:destinations]
|
12
|
+
@starting_point = attributes[:starting_point]
|
13
|
+
@indivative_price = attributes[:indivative_price]
|
14
|
+
@rating = attributes[:rating]
|
15
|
+
@pictures = attributes[:pictures]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Models
|
3
|
+
class Destination
|
4
|
+
attr_accessor :provider_id, :name, :country, :unlocode, :iata, :destination_type
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@provider_id = attributes[:provider_id]
|
8
|
+
@name = attributes[:name]
|
9
|
+
@country = attributes[:country]
|
10
|
+
@unlocode = attributes[:unlocode]
|
11
|
+
@iata = attributes[:iata]
|
12
|
+
@destination_type = attributes[:destination_type]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Models
|
3
|
+
class ImageFormat
|
4
|
+
attr_accessor :provider_id, :width, :height, :comment
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@provider_id = attributes[:provider_id]
|
8
|
+
@width = attributes[:width]
|
9
|
+
@height = attributes[:height]
|
10
|
+
@comment = attributes[:comment]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Models
|
3
|
+
class Location
|
4
|
+
attr_accessor :provider_id, :name, :country, :start_location
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@provider_id = attributes[:provider_id]
|
8
|
+
@name = attributes[:name]
|
9
|
+
@country = attributes[:country]
|
10
|
+
@start_location = attributes[:start_location]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Models
|
3
|
+
class TopCategory
|
4
|
+
attr_accessor :provider_id, :name, :link, :picture, :rating
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@provider_id = attributes[:provider_id]
|
8
|
+
@name = attributes[:name]
|
9
|
+
@link = attributes[:link]
|
10
|
+
@picture = attributes[:picture]
|
11
|
+
@rating = attributes[:rating]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Parsers
|
3
|
+
class Categories < GetYourGuide::Parsers::Default
|
4
|
+
def initialize(api_xml)
|
5
|
+
super
|
6
|
+
@parsed_categories = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def process
|
10
|
+
@api_xml.xpath('//category').each do |category_xml|
|
11
|
+
parsed_category = parse_simgle_category category_xml
|
12
|
+
@parsed_categories << parsed_category
|
13
|
+
end
|
14
|
+
|
15
|
+
@parsed_categories
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_simgle_category(category_xml)
|
19
|
+
category_attributes = {
|
20
|
+
:provider_id => category_xml.attr('id').to_i,
|
21
|
+
:name => category_xml.xpath('name').children.inner_text
|
22
|
+
}
|
23
|
+
|
24
|
+
GetYourGuide::Models::Category.new(category_attributes)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Parsers
|
3
|
+
class Default
|
4
|
+
def initialize(api_xml)
|
5
|
+
@api_xml = api_xml
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def get_locations_list(product_xml)
|
11
|
+
locations = []
|
12
|
+
|
13
|
+
product_xml.xpath('destination').children.xpath('location').each do |location|
|
14
|
+
location_attributes = {
|
15
|
+
:provider_id => location.attr('id').to_i,
|
16
|
+
:name => location.inner_text,
|
17
|
+
:country => location.attr('country'),
|
18
|
+
:start_location => !location.attr('start_location').nil?
|
19
|
+
}
|
20
|
+
|
21
|
+
locations << GetYourGuide::Models::Location.new(location_attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
locations
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_categories_list(product_xml)
|
28
|
+
categories = []
|
29
|
+
|
30
|
+
product_xml.xpath('categories').children.each do |category|
|
31
|
+
category_attributes = {
|
32
|
+
:provider_id => category.attr('id').to_i,
|
33
|
+
:name => category.inner_text
|
34
|
+
}
|
35
|
+
|
36
|
+
categories << GetYourGuide::Models::Category.new(category_attributes)
|
37
|
+
end
|
38
|
+
|
39
|
+
categories
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_pictures_list(product_xml)
|
43
|
+
pictures = []
|
44
|
+
|
45
|
+
product_xml.xpath('pictures').children.children.each do |picture|
|
46
|
+
pictures << picture.inner_text if picture.inner_text != ''
|
47
|
+
end
|
48
|
+
|
49
|
+
pictures
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_indivative_price(product_xml)
|
53
|
+
product_xml.xpath('price').children.first.children.each do |price|
|
54
|
+
return price.children.inner_text.to_f if price.attr('currency') == 'EUR'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_starting_point_list(product_xml)
|
59
|
+
{
|
60
|
+
:lat => product_xml.xpath('destination').children.last.children.first.inner_text,
|
61
|
+
:lng => product_xml.xpath('destination').children.last.children.last.inner_text,
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Parsers
|
3
|
+
class Destinations < GetYourGuide::Parsers::Default
|
4
|
+
def initialize(api_xml)
|
5
|
+
super
|
6
|
+
@parsed_destinations = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def process
|
10
|
+
@api_xml.xpath('//destination').each do |destination_xml|
|
11
|
+
parsed_destination = parse_simgle_destination destination_xml
|
12
|
+
@parsed_destinations << parsed_destination
|
13
|
+
end
|
14
|
+
|
15
|
+
@parsed_destinations
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_simgle_destination(destination_xml)
|
19
|
+
destination_attributes = {
|
20
|
+
:provider_id => destination_xml.attr('id').to_i,
|
21
|
+
:name => destination_xml.xpath('name').children.inner_text,
|
22
|
+
:country => destination_xml.attr('country').to_s,
|
23
|
+
:destination_type => destination_xml.attr('type').to_s
|
24
|
+
}
|
25
|
+
|
26
|
+
if destination_xml.xpath('.//alias').children.size > 0
|
27
|
+
destination_attributes[:unlocode] = destination_xml.xpath('.//alias').children.first.inner_text
|
28
|
+
destination_attributes[:iata] = destination_xml.xpath('.//alias').children.last.inner_text
|
29
|
+
end
|
30
|
+
|
31
|
+
GetYourGuide::Models::Destination.new(destination_attributes)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Parsers
|
3
|
+
class ImageFormats < GetYourGuide::Parsers::Default
|
4
|
+
def initialize(api_xml)
|
5
|
+
super
|
6
|
+
@parsed_image_formats = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def process
|
10
|
+
@api_xml.xpath('//image_format').each do |image_format_xml|
|
11
|
+
parsed_image_format = parse_simgle_image_format image_format_xml
|
12
|
+
@parsed_image_formats << parsed_image_format
|
13
|
+
end
|
14
|
+
|
15
|
+
@parsed_image_formats
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_simgle_image_format(image_format_xml)
|
19
|
+
image_format_attributes = {
|
20
|
+
:provider_id => image_format_xml.attr('id').to_i,
|
21
|
+
:width => image_format_xml.xpath('width').children.inner_text.to_i,
|
22
|
+
:height => image_format_xml.xpath('height').children.inner_text.to_i,
|
23
|
+
:comment => image_format_xml.xpath('comment').children.inner_text
|
24
|
+
}
|
25
|
+
|
26
|
+
GetYourGuide::Models::ImageFormat.new(image_format_attributes)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Parsers
|
3
|
+
class Products < GetYourGuide::Parsers::Default
|
4
|
+
def initialize(api_xml)
|
5
|
+
super
|
6
|
+
@parsed_activities = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def process
|
10
|
+
@api_xml.xpath('//product').each do |product_xml|
|
11
|
+
parsed_activity = parse_simgle_product product_xml
|
12
|
+
@parsed_activities << parsed_activity
|
13
|
+
end
|
14
|
+
|
15
|
+
@parsed_activities
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_simgle_product(product_xml)
|
19
|
+
attributes = {
|
20
|
+
:provider_id => product_xml.attr('id').to_i,
|
21
|
+
:title => product_xml.xpath('title').children.inner_text,
|
22
|
+
:abstract => product_xml.xpath('abstract').children.inner_text,
|
23
|
+
:categories => get_categories_list(product_xml),
|
24
|
+
:locations => get_locations_list(product_xml),
|
25
|
+
:starting_point => get_starting_point_list(product_xml),
|
26
|
+
:indivative_price => get_indivative_price(product_xml),
|
27
|
+
:rating => product_xml.xpath('rating').children.inner_text.to_f,
|
28
|
+
:pictures => get_pictures_list(product_xml)
|
29
|
+
}
|
30
|
+
|
31
|
+
GetYourGuide::Models::Activity.new attributes
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GetYourGuide
|
2
|
+
module Parsers
|
3
|
+
class TopCategories < GetYourGuide::Parsers::Default
|
4
|
+
def initialize(api_xml)
|
5
|
+
super
|
6
|
+
@parsed_categories = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def process
|
10
|
+
@api_xml.xpath('//category').each do |category_xml|
|
11
|
+
parsed_category = parse_simgle_category category_xml
|
12
|
+
@parsed_categories << parsed_category
|
13
|
+
end
|
14
|
+
|
15
|
+
@parsed_categories
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_simgle_category(category_xml)
|
19
|
+
category_attributes = {
|
20
|
+
:provider_id => category_xml.attr('id').to_i,
|
21
|
+
:name => category_xml.xpath('name').children.inner_text,
|
22
|
+
:link => category_xml.xpath('link').children.inner_text,
|
23
|
+
:picture => category_xml.xpath('picture').children.inner_text,
|
24
|
+
:rating => category_xml.xpath('rating').children.inner_text.to_i
|
25
|
+
}
|
26
|
+
|
27
|
+
GetYourGuide::Models::TopCategory.new(category_attributes)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: getyourguide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rémi Delhaye
|
8
|
+
- Libertrip
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: nokogiri
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.5'
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 1.5.0
|
52
|
+
type: :runtime
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - "~>"
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '1.5'
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: httpclient
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.3'
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 2.3.1
|
72
|
+
type: :runtime
|
73
|
+
prerelease: false
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.3'
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.3.1
|
82
|
+
description: A simple ruby client for GetYourGuide partner XML API
|
83
|
+
email:
|
84
|
+
- remi@libertrip.com
|
85
|
+
- maxime@libertrip.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rvmrc"
|
92
|
+
- ".rvmrc.01.29.2015-18:48:37"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- getyourguide.gemspec
|
98
|
+
- lib/getyourguide.rb
|
99
|
+
- lib/getyourguide/api_client.rb
|
100
|
+
- lib/getyourguide/errors/api_error.rb
|
101
|
+
- lib/getyourguide/models/activity.rb
|
102
|
+
- lib/getyourguide/models/category.rb
|
103
|
+
- lib/getyourguide/models/destination.rb
|
104
|
+
- lib/getyourguide/models/image_format.rb
|
105
|
+
- lib/getyourguide/models/location.rb
|
106
|
+
- lib/getyourguide/models/top_category.rb
|
107
|
+
- lib/getyourguide/parsers/categories.rb
|
108
|
+
- lib/getyourguide/parsers/default.rb
|
109
|
+
- lib/getyourguide/parsers/destinations.rb
|
110
|
+
- lib/getyourguide/parsers/image_formats.rb
|
111
|
+
- lib/getyourguide/parsers/products.rb
|
112
|
+
- lib/getyourguide/parsers/top_categories.rb
|
113
|
+
- lib/getyourguide/version.rb
|
114
|
+
homepage: https://github.com/Libertrip/getyourguide
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.2.2
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: A simple ruby on rails client for GetYourGuide partner XML API
|
138
|
+
test_files: []
|