tourcms 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
- gem 'xml-object'
5
+ gem 'nokogiri'
6
6
 
7
7
  # Add dependencies to develop your gem here.
8
8
  # Include everything needed to run rake, tests, features, etc.
@@ -6,10 +6,10 @@ GEM
6
6
  bundler (~> 1.0.0)
7
7
  git (>= 1.2.5)
8
8
  rake
9
+ nokogiri (1.4.4)
9
10
  rake (0.8.7)
10
11
  rcov (0.9.9)
11
12
  shoulda (2.11.3)
12
- xml-object (0.9.93)
13
13
 
14
14
  PLATFORMS
15
15
  ruby
@@ -17,6 +17,6 @@ PLATFORMS
17
17
  DEPENDENCIES
18
18
  bundler (~> 1.0.0)
19
19
  jeweler (~> 1.5.2)
20
+ nokogiri
20
21
  rcov
21
22
  shoulda
22
- xml-object
data/README.md CHANGED
@@ -12,7 +12,7 @@ Using the library is as simple as creating a **TourCMS::Connection** object:
12
12
 
13
13
  conn = TourCMS::Connection.new(marketplace_id, private_key, result_type)
14
14
 
15
- Your Marketplace ID and Private Key can be found in the TourCMS Partner Portal. The result type can be one of **obj** or **raw** where **raw** will return the raw XML from the API and **obj** will return an XMLObject using the [XML-Object Gem](https://github.com/jordi/xml-object).
15
+ Your Marketplace ID and Private Key can be found in the TourCMS Partner Portal. The result type can be one of **hash** or **raw** where **raw** will return the raw XML from the API and **hash** will return a Ruby Hash of the result.
16
16
 
17
17
  ### Working with your connection in Raw mode
18
18
 
@@ -31,30 +31,29 @@ Your Marketplace ID and Private Key can be found in the TourCMS Partner Portal.
31
31
  => ""<?xml version="1.0" encoding="utf-8" ?><response><request>GET /p/channels/list.xml</request>
32
32
  <error>OK</error><channel>(...)</channel></response>"
33
33
 
34
- ### Working with your connection in Obj mode
34
+ ### Working with your connection in Hash mode
35
35
 
36
36
  # Instantiate the connection
37
- conn = TourCMS::Connection.new("12345", "mydeepsecret", "obj")
37
+ conn = TourCMS::Connection.new("12345", "mydeepsecret", "hash")
38
38
  # Check we're working
39
39
  obj = conn.api_rate_limit_status
40
-
41
- Note: XML-Object **does not support .inspect** so obj will return empty. XML-Object uses method_missing to access object properties so **you will need to know which property you're trying to access** beforehand -- Check the API docs.
42
-
43
- obj.hourly_limit
40
+ => {:request=>"GET /api/rate_limit_status.xml", :remaining_hits=>1999, :error=>"OK", :hourly_limit=>2000}
41
+ obj[:hourly_limit]
44
42
  => 2000
45
43
  # List the channels we have access to
46
44
  obj = conn.list_channels
47
- obj.channel
48
- => [Array of Channel Objects]
49
- obj.channel.first.channel_name
45
+ => {Hash of all connected TourCMS channels and their properties}
46
+ obj[:channel].count
47
+ => 100 # Integer representing how many TourCMS channels you're connected to.
48
+ obj[:channel].first[:channel_name]
50
49
  => "My Adventure Tour Operator"
51
50
  # Show a particular channel
52
51
  obj = conn.show_channel(1234567)
53
- obj.channel.channel_id
52
+ obj[:channel][:channel_id]
54
53
  => "1234567"
55
54
  # Search for all tours in GB
56
55
  obj = conn.search_tours(:country => "GB")
57
- obj.tour.first.tour_name
56
+ obj[:tour].first[:tour_name]
58
57
  => "Canyoning"
59
58
 
60
59
  ### Passing parameters
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -9,67 +9,67 @@ module TourCMS
9
9
  end
10
10
 
11
11
  def api_rate_limit_status(channel = 0)
12
- return_result(request("/api/rate_limit_status.xml", channel))
12
+ request("/api/rate_limit_status.xml", channel)
13
13
  end
14
14
 
15
15
  def list_channels
16
- return_result(request("/p/channels/list.xml"))
16
+ request("/p/channels/list.xml")
17
17
  end
18
18
 
19
19
  def show_channel(channel)
20
- return_result(request("/c/channel/show.xml", channel))
20
+ request("/c/channel/show.xml", channel)
21
21
  end
22
22
 
23
23
  def search_tours(params = {}, channel = 0)
24
24
  if channel == 0
25
- return_result(request("/p/tours/search.xml", 0, params))
25
+ request("/p/tours/search.xml", 0, params)
26
26
  else
27
- return_result(request("/c/tours/search.xml", channel, params))
27
+ request("/c/tours/search.xml", channel, params)
28
28
  end
29
29
  end
30
30
 
31
31
  def search_hotels_range(params = {}, tour = "", channel = 0)
32
32
  if channel == 0
33
- return_result(request("/p/hotels/search_range.xml", 0, params.merge({"single_tour_id" => tour})))
33
+ request("/p/hotels/search_range.xml", 0, params.merge({"single_tour_id" => tour}))
34
34
  else
35
- return_result(request("/c/hotels/search_range.xml", channel, params.merge({"single_tour_id" => tour})))
35
+ request("/c/hotels/search_range.xml", channel, params.merge({"single_tour_id" => tour}))
36
36
  end
37
37
  end
38
38
 
39
39
  def search_hotels_specific(params = {}, tour = "", channel = 0)
40
40
  if channel == 0
41
- return_result(request("/p/hotels/search-avail.xml", 0, params.merge({"single_tour_id" => tour})))
41
+ request("/p/hotels/search-avail.xml", 0, params.merge({"single_tour_id" => tour}))
42
42
  else
43
- return_result(request("/c/hotels/search-avail.xml", channel, params.merge({"single_tour_id" => tour})))
43
+ request("/c/hotels/search-avail.xml", channel, params.merge({"single_tour_id" => tour}))
44
44
  end
45
45
  end
46
46
 
47
47
  def list_tours(channel = 0)
48
48
  if channel == 0
49
- return_result(request("/p/tours/list.xml"))
49
+ request("/p/tours/list.xml")
50
50
  else
51
- return_result(request("/c/tours/list.xml", channel))
51
+ request("/c/tours/list.xml", channel)
52
52
  end
53
53
  end
54
54
 
55
55
  def list_tour_images(channel = 0)
56
56
  if channel == 0
57
- return_result(request("/p/tours/images/list.xml"))
57
+ request("/p/tours/images/list.xml")
58
58
  else
59
- return_result(request("/c/tours/images/list.xml", channel))
59
+ request("/c/tours/images/list.xml", channel)
60
60
  end
61
61
  end
62
62
 
63
63
  def show_tour(tour, channel)
64
- return_result(request("/c/tour/show.xml", channel, {"id" => tour}))
64
+ request("/c/tour/show.xml", channel, {"id" => tour})
65
65
  end
66
66
 
67
67
  def show_tour_departures(tour, channel)
68
- return_result(request("/c/tour/datesprices/dep/show.xml", channel, {"id" => tour}))
68
+ request("/c/tour/datesprices/dep/show.xml", channel, {"id" => tour})
69
69
  end
70
70
 
71
71
  def show_tour_freesale(tour, channel)
72
- return_result(request("/c/tour/datesprices/freesale/show.xml", channel, {"id" => tour}))
72
+ request("/c/tour/datesprices/freesale/show.xml", channel, {"id" => tour})
73
73
  end
74
74
 
75
75
  private
@@ -86,7 +86,7 @@ module TourCMS
86
86
  if param_hash.empty?
87
87
  res = ""
88
88
  else
89
- qs = param_hash.stringify_keys.reject{|k,v| v.nil? || v.empty?}.collect{|k,v|"#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
89
+ qs = param_hash.stringify.reject{|k,v| v.nil? || v.empty?}.collect{|k,v|"#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
90
90
  qs.empty? ? res = "" : res = "?#{qs}"
91
91
  end
92
92
  res
@@ -107,17 +107,8 @@ module TourCMS
107
107
 
108
108
  headers = {"Content-type" => "text/xml", "charset" => "utf-8", "Date" => req_time.strftime("%a, %d %b %Y %H:%M:%S GMT"),
109
109
  "Authorization" => "TourCMS #{channel}:#{@marketp_id}:#{signature}" }
110
-
111
- begin
112
- response = open(url, headers).read
113
- rescue Exception => e
114
- puts "Caught exception opening #{url}"
115
- puts e.message
116
- puts e.backtrace.inspect
117
- rescue OpenURI::HTTPError => http_e
118
- puts "Received HTTP Error opening #{url}"
119
- puts http_e.io.status[0].to_s
120
- end
110
+
111
+ @result_type == "raw" ? open(url, headers) : doc = Hash.from_xml(open(url, headers))[:response]
121
112
  end
122
113
  end
123
114
  end
@@ -1,10 +1,67 @@
1
- module TourCMS
2
- class Hash
3
- def stringify_keys
4
- inject({}) do |options, (key, value)|
5
- options[key.to_s] = value.to_s
6
- options
1
+ class Hash
2
+ def stringify
3
+ inject({}) do |options, (key, value)|
4
+ options[key.to_s] = value.to_s
5
+ options
6
+ end
7
+ end
8
+
9
+ class << self
10
+ def from_xml(xml_io)
11
+ begin
12
+ result = Nokogiri::XML(xml_io)
13
+ return { result.root.name.to_sym => xml_node_to_hash(result.root)}
14
+ rescue Exception => e
15
+ raise StandardError, "Could not parse TourCMS XML Response. Server error?"
7
16
  end
17
+ end
18
+
19
+ def xml_node_to_hash(node)
20
+ # If we are at the root of the document, start the hash
21
+ if node.element?
22
+ result_hash = {}
23
+ if node.attributes != {}
24
+ result_hash[:attributes] = {}
25
+ node.attributes.keys.each do |key|
26
+ result_hash[:attributes][node.attributes[key].name.to_sym] = prepare(node.attributes[key].value)
27
+ end
28
+ end
29
+ if node.children.size > 0
30
+ node.children.each do |child|
31
+ result = xml_node_to_hash(child)
32
+
33
+ if child.name == "text" || child.name == "#cdata-section"
34
+ unless child.next_sibling || child.previous_sibling
35
+ return prepare(result)
36
+ end
37
+ elsif result_hash[child.name.to_sym]
38
+ if result_hash[child.name.to_sym].is_a?(Object::Array)
39
+ result_hash[child.name.to_sym] << prepare(result)
40
+ else
41
+ result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << prepare(result)
42
+ end
43
+ else
44
+ result_hash[child.name.to_sym] = prepare(result)
45
+ end
46
+ end
47
+
48
+ return result_hash
49
+ else
50
+ return result_hash
51
+ end
52
+ else
53
+ return prepare(node.content.to_s)
54
+ end
55
+ end
56
+
57
+ def prepare(data)
58
+ data = "" if data == "\n\t"
59
+ (data.class == String && data.to_i.to_s == data) ? data.to_i : data
8
60
  end
9
61
  end
62
+
63
+ def to_struct(struct_name)
64
+ Struct.new(struct_name,*keys).new(*values)
65
+ end
66
+
10
67
  end
@@ -4,7 +4,8 @@ require 'openssl'
4
4
  require 'base64'
5
5
  require 'cgi'
6
6
  require 'open-uri'
7
- require 'xml-object'
7
+ require 'rubygems'
8
+ require 'nokogiri'
8
9
 
9
10
  require 'tour_cms/hash'
10
11
  require 'tour_cms/connection'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tourcms}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Kremer"]
12
- s.date = %q{2011-03-28}
12
+ s.date = %q{2011-04-19}
13
13
  s.description = %q{A simple Ruby wrapper for interacting with the TourCMS API}
14
14
  s.email = %q{alex@flextrip.com}
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.homepage = %q{http://github.com/flextrip/tourcms}
34
34
  s.licenses = ["MIT"]
35
35
  s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.3.7}
36
+ s.rubygems_version = %q{1.7.2}
37
37
  s.summary = %q{A Ruby Library for the TourCMS API}
38
38
  s.test_files = [
39
39
  "test/helper.rb",
@@ -41,18 +41,17 @@ Gem::Specification.new do |s|
41
41
  ]
42
42
 
43
43
  if s.respond_to? :specification_version then
44
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
44
  s.specification_version = 3
46
45
 
47
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
- s.add_runtime_dependency(%q<xml-object>, [">= 0"])
47
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
49
48
  s.add_development_dependency(%q<shoulda>, [">= 0"])
50
49
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
50
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
52
51
  s.add_development_dependency(%q<rcov>, [">= 0"])
53
52
  s.add_runtime_dependency(%q<xml-object>, [">= 0"])
54
53
  else
55
- s.add_dependency(%q<xml-object>, [">= 0"])
54
+ s.add_dependency(%q<nokogiri>, [">= 0"])
56
55
  s.add_dependency(%q<shoulda>, [">= 0"])
57
56
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
57
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
@@ -60,7 +59,7 @@ Gem::Specification.new do |s|
60
59
  s.add_dependency(%q<xml-object>, [">= 0"])
61
60
  end
62
61
  else
63
- s.add_dependency(%q<xml-object>, [">= 0"])
62
+ s.add_dependency(%q<nokogiri>, [">= 0"])
64
63
  s.add_dependency(%q<shoulda>, [">= 0"])
65
64
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
65
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tourcms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Kremer
@@ -15,10 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-28 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-04-19 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
@@ -28,11 +28,11 @@ dependencies:
28
28
  segments:
29
29
  - 0
30
30
  version: "0"
31
- type: :runtime
32
- name: xml-object
33
- prerelease: false
34
31
  version_requirements: *id001
32
+ name: nokogiri
33
+ prerelease: false
35
34
  - !ruby/object:Gem::Dependency
35
+ type: :development
36
36
  requirement: &id002 !ruby/object:Gem::Requirement
37
37
  none: false
38
38
  requirements:
@@ -42,11 +42,11 @@ dependencies:
42
42
  segments:
43
43
  - 0
44
44
  version: "0"
45
- type: :development
45
+ version_requirements: *id002
46
46
  name: shoulda
47
47
  prerelease: false
48
- version_requirements: *id002
49
48
  - !ruby/object:Gem::Dependency
49
+ type: :development
50
50
  requirement: &id003 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
@@ -58,11 +58,11 @@ dependencies:
58
58
  - 0
59
59
  - 0
60
60
  version: 1.0.0
61
- type: :development
61
+ version_requirements: *id003
62
62
  name: bundler
63
63
  prerelease: false
64
- version_requirements: *id003
65
64
  - !ruby/object:Gem::Dependency
65
+ type: :development
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
@@ -74,11 +74,11 @@ dependencies:
74
74
  - 5
75
75
  - 2
76
76
  version: 1.5.2
77
- type: :development
77
+ version_requirements: *id004
78
78
  name: jeweler
79
79
  prerelease: false
80
- version_requirements: *id004
81
80
  - !ruby/object:Gem::Dependency
81
+ type: :development
82
82
  requirement: &id005 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
@@ -88,11 +88,11 @@ dependencies:
88
88
  segments:
89
89
  - 0
90
90
  version: "0"
91
- type: :development
91
+ version_requirements: *id005
92
92
  name: rcov
93
93
  prerelease: false
94
- version_requirements: *id005
95
94
  - !ruby/object:Gem::Dependency
95
+ type: :runtime
96
96
  requirement: &id006 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -102,10 +102,9 @@ dependencies:
102
102
  segments:
103
103
  - 0
104
104
  version: "0"
105
- type: :runtime
105
+ version_requirements: *id006
106
106
  name: xml-object
107
107
  prerelease: false
108
- version_requirements: *id006
109
108
  description: A simple Ruby wrapper for interacting with the TourCMS API
110
109
  email: alex@flextrip.com
111
110
  executables: []
@@ -128,7 +127,6 @@ files:
128
127
  - test/helper.rb
129
128
  - test/test_tourcms.rb
130
129
  - tourcms.gemspec
131
- has_rdoc: true
132
130
  homepage: http://github.com/flextrip/tourcms
133
131
  licenses:
134
132
  - MIT
@@ -158,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
156
  requirements: []
159
157
 
160
158
  rubyforge_project:
161
- rubygems_version: 1.3.7
159
+ rubygems_version: 1.7.2
162
160
  signing_key:
163
161
  specification_version: 3
164
162
  summary: A Ruby Library for the TourCMS API