kigo 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 896128c548ca3f06e03ba17a5dabfdca9b78be99
4
+ data.tar.gz: 5a9bb28d0ce254bf634eb6ca2ca0b695b648e907
5
+ SHA512:
6
+ metadata.gz: 69135bf59c410516953754a37c4ddd686387aa341d40872c4c584d83b05cfa50b3ec595fe90fd37d1538ad504e11da6a1deeaf11e70cf51483c6b2db8face112
7
+ data.tar.gz: cc2bc838c594616533f760a33059d142d03c60c59794cbcae332fecc3b7f9d8f54a6fbc6d75671030994efd88289e30895a9dc5851fc743d586e84798254e5c0
@@ -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,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kigo.gemspec
4
+ gemspec
5
+
6
+ gem 'typhoeus'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rijaludin Muhsin
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,45 @@
1
+ # Kigo
2
+
3
+ Kigo is an online vacation rental software. http://kigo.net
4
+
5
+ They also provide their services to be accessed via API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'kigo'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kigo
20
+
21
+ ## Configuration
22
+
23
+ Add an initializer e.g config/initializers/kigo.rb
24
+
25
+ You will get the username and password once you register.
26
+
27
+ ```ruby
28
+ Kigo.configure do |config|
29
+ config.username = 'your username'
30
+ config.password = 'your password'
31
+ end
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ NOTE: Still in development
37
+
38
+ Basically to use the gem is to call the API service name in underscore.
39
+
40
+ For example when you want to access /diffPropertyCalendarReservations you can use:
41
+
42
+ ```ruby
43
+ diff_id = "diff id string"
44
+ Kigo.diff_property_calendar_reservations diff_id
45
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kigo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kigo"
8
+ spec.version = Kigo::VERSION
9
+ spec.authors = ["Rijaludin Muhsin"]
10
+ spec.email = ["rijaludinmuhsin@gmail.com"]
11
+ spec.summary = %q{Ruby helper for Kigo API}
12
+ spec.description = %q{Ruby helper for Kigo 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.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,175 @@
1
+ require "kigo/version"
2
+ require "kigo/configuration"
3
+ require "typhoeus"
4
+
5
+ module Kigo
6
+ APIUrl = 'https://app.kigo.net/api/ra/v1'
7
+
8
+ def self.wrap_request(end_point, request_method, data={}, headers={})
9
+ basic_auth = { username: Kigo.configuration.username, password: Kigo.configuration.password }
10
+ encoded_auth = "Basic #{Base64.strict_encode64("#{basic_auth[:username]}:#{basic_auth[:password]}")}"
11
+ data = self.filter_params(data)
12
+ request_options = { method: request_method, headers: headers.merge(
13
+ { 'Authorization' => encoded_auth,
14
+ 'Content-Type' => 'application/json' }
15
+ ) }
16
+ request_options = request_options.merge(request_method == :post ? { body: data.to_json } : { params: data.to_json })
17
+ Typhoeus::Request.new("#{APIUrl}#{end_point}", request_options)
18
+ end
19
+
20
+ def self.access_multiple(resources=[])
21
+ hydra = Typhoeus::Hydra.new
22
+ request_responses = []
23
+
24
+ resources.each do |resource|
25
+ request = self.wrap_request(resource[:end_point], resource[:verb], resource[:params], resource[:headers])
26
+ request.on_complete do |response|
27
+ request_responses << self.parse_response(response)
28
+ end
29
+ hydra.queue(request)
30
+ end
31
+ hydra.run
32
+ request_responses
33
+ end
34
+
35
+ def self.access(end_point, request_method, data={}, headers={})
36
+ request = self.wrap_request(end_point, request_method, data, headers)
37
+ request.on_complete do |response|
38
+ return self.parse_response(response)
39
+ end
40
+ hydra = Typhoeus::Hydra.new
41
+ hydra.queue(request)
42
+ hydra.run
43
+ end
44
+
45
+ def self.parse_response(response)
46
+ if response.success?
47
+ begin
48
+ result = JSON.parse(response.body)
49
+ return result["API_RESULT_CODE"] == "E_OK" ? result["API_REPLY"] : { 'error' => "#{result["API_RESULT_CODE"]} #{result["API_RESULT_TEXT"]}" }
50
+ rescue
51
+ return { 'error' => "Error parsing reply" }
52
+ end
53
+ else
54
+ return { 'error' => "Response error. #{response.code} #{response.body}" }
55
+ end
56
+ end
57
+
58
+ def self.filter_params(hash)
59
+ filtered_attr = {}
60
+ hash.each do |param_name, value|
61
+ if value.is_a? Hash
62
+ filtered_attr = filtered_attr.merge(param_name => filter_params(value))
63
+ elsif value.is_a? Array
64
+ filtered_attr = filtered_attr.merge(param_name => filter_array_params(value))
65
+ else
66
+ if value.class == ActionDispatch::Http::UploadedFile
67
+ filtered_attr = filtered_attr.merge(param_name => value.tempfile)
68
+ else
69
+ filtered_attr = filtered_attr.merge(param_name => value)
70
+ end
71
+ end
72
+ end
73
+ return filtered_attr
74
+ end
75
+
76
+ def self.filter_array_params(array)
77
+ return array.map { |a| a.is_a?(Hash) ? self.filter_params(a) : a }
78
+ end
79
+
80
+ def self.ping
81
+ self.access('/ping', :post, {})
82
+ end
83
+
84
+
85
+ # Reservations
86
+ def self.diff_property_calendar_reservations(diff_id = nil)
87
+ self.access('/diffPropertyCalendarReservations', :post, { 'DIFF_ID' => diff_id })
88
+ end
89
+
90
+ def self.createConfirmedReservation(params)
91
+ # params example:
92
+ # {
93
+ # "PROP_ID" => 1434,
94
+ # "RES_CHECK_IN" => "2011-07-21",
95
+ # "RES_CHECK_OUT" => "2011-07-26",
96
+ # "RES_N_ADULTS" => 2,
97
+ # "RES_N_CHILDREN" => 1,
98
+ # "RES_N_BABIES" => 0,
99
+ # "RES_GUEST" => {
100
+ # "RES_GUEST_FIRSTNAME" => "Robert",
101
+ # "RES_GUEST_LASTNAME" => "Roquefort",
102
+ # "RES_GUEST_EMAIL" => "robert@yahoo.co.uk",
103
+ # "RES_GUEST_PHONE" => "",
104
+ # "RES_GUEST_COUNTRY" => "GB"
105
+ # },
106
+ # "RES_COMMENT" => "",
107
+ # "RES_COMMENT_GUEST" => "",
108
+ # "RES_UDRA" => [
109
+ # {
110
+ # "UDRA_ID" => 161,
111
+ # "UDRA_CHOICE_ID" => 199
112
+ # },
113
+ # {
114
+ # "UDRA_ID" => 162,
115
+ # "UDRA_TEXT" => "John Smith told me about you!"
116
+ # }
117
+ # ]
118
+ # }
119
+ self.access('/createConfirmedReservation', :post, params)
120
+ end
121
+
122
+ #Properties
123
+ def self.list_properties
124
+ self.access('/listProperties', :post)
125
+ end
126
+
127
+ def self.read_property(property_id)
128
+ self.access('/readProperty', :post, { 'PROP_ID' => property_id })
129
+ end
130
+
131
+ # Pricing
132
+ def self.read_property_pricing_setup(property_id)
133
+ self.access('/readPropertyPricingSetup', :post, { 'PROP_ID' => property_id })
134
+ end
135
+
136
+ def self.diff_property_pricing_setup(diff_id = nil)
137
+ self.access('/diffPropertyPricingSetup', :post, { 'DIFF_ID' => diff_id })
138
+ end
139
+
140
+ # Example of pricing hash:
141
+ # { "RENT" => {
142
+ # "PERGUEST_CHARGE" => nil,
143
+ # "PERIODS" => [
144
+ # { "CHECK_IN" => "2014-01-01",
145
+ # "CHECK_OUT" => "2014-03-01",
146
+ # "NAME" => "Winter 2014",
147
+ # "STAY_MIN" => { "UNIT" => "NIGHT", "NUMBER" => 3 },
148
+ # "WEEKLY" => false,
149
+ # "NIGHTLY_AMOUNTS" => [
150
+ # { "GUESTS_FROM" => 1,
151
+ # "WEEK_NIGHTS" => [ 1, 2, 3, 4, 5, 6, 7 ],
152
+ # "STAY_FROM" => { "UNIT" => "NIGHT", "NUMBER" => 1 },
153
+ # "AMOUNT" => "100.00"
154
+ # }
155
+ # ]
156
+ # },
157
+ # { "CHECK_IN" => "2014-03-01",
158
+ # "CHECK_OUT" => "2014-05-31",
159
+ # "NAME" => "",
160
+ # "STAY_MIN" => { "UNIT" => "NIGHT", "NUMBER" => 7 },
161
+ # "WEEKLY" => true,
162
+ # "WEEKLY_AMOUNTS" => [
163
+ # { "GUESTS_FROM" => 1,
164
+ # "AMOUNT" => "650.00"
165
+ # }
166
+ # ]
167
+ # }
168
+ # ]
169
+ # }
170
+ # }
171
+ def self.update_property_pricing_setup(property_id, pricing)
172
+ self.access('/updatePropertyPricingSetup', :post, { 'PROP_ID' => property_id, 'PRICING' => pricing })
173
+ end
174
+
175
+ end
@@ -0,0 +1,26 @@
1
+ module Kigo
2
+ class Configuration
3
+ attr_accessor :username, :password
4
+ end
5
+
6
+ class << self
7
+ attr_accessor :configuration
8
+ end
9
+
10
+ # Configure Kigo someplace sensible,
11
+ # like config/initializers/kigo.rb
12
+ #
13
+ # @example
14
+ # Kigo.configure do |config|
15
+ # config.username = 'your username'
16
+ # config.password = 'your password'
17
+ # end
18
+
19
+ def self.configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+
23
+ def self.configure
24
+ yield(configuration)
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Kigo
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kigo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rijaludin Muhsin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-25 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ description: Ruby helper for Kigo API
42
+ email:
43
+ - rijaludinmuhsin@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - kigo.gemspec
54
+ - lib/kigo.rb
55
+ - lib/kigo/configuration.rb
56
+ - lib/kigo/version.rb
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Ruby helper for Kigo API
81
+ test_files: []