vacation_rentals_ical_adapters 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d526b9ce53b50de844cffe21affd2b2d166f9fa
4
+ data.tar.gz: aac604fb44bd607c8b7a9b2695abaf480a1f1bda
5
+ SHA512:
6
+ metadata.gz: 1725927e2bac0ce6372c0eb73d08d2330556c56753ff10b86189c5c7b9878688c3b9693fe43ee16428bd3d572094aef299751d1c64082e3cc14b12b8575a702e
7
+ data.tar.gz: d3073fdb915421eaae2164e4eacdcfb9651a89924ea2e204a7f42b62ab494ede12f61a5c2f6060e26c6e83fa1045472e3d716ac2c295eaa7f293741e36e42a2f
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vacation_rentals_ical_adapters.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Karol Galanciak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # VacationRentalsIcalAdapters
2
+
3
+ Gem for converting different formats from various vacation rental distribution channels to iCal format. So far it handles the following adapters:
4
+
5
+ - iCal adapter: returns not changed iCal body if it is indeed iCal format
6
+ - XML Arkiane Adapter - transforms XML response from xml.arkiane.com for given property into iCal format
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'vacation_rentals_ical_adapters'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install vacation_rentals_ical_adapters
23
+
24
+ ## Usage
25
+
26
+ The public API is limited to `VacationRentalsIcalAdapters::Parser#to_ical` method, here's example how to use it:
27
+
28
+ ``` ruby
29
+ source = "http://xml.arkiane.com/xml_v2.asp?app=X&clt=X&top=-1&qry=to_get_planning@top_id=X,@lot_ref=X"
30
+ arkiane_xml_body = %q{<?xml version='1.0' encoding='ISO-8859-1'?>
31
+ <QRY-CLT1XXX-TOP-1>
32
+ <LINE>
33
+ <Planning>
34
+ <l_plng_no>1</l_plng_no>
35
+ <l_imme_no>1</l_imme_no>
36
+ <l_lot_no>12</l_lot_no>
37
+ <l_ref>XXX</l_ref>
38
+ <o_debut>27/08/2016</o_debut>
39
+ <o_fin>10/12/2016</o_fin>
40
+ <o_type>YYY</o_type>
41
+ </Planning>
42
+ </LINE>
43
+ <LINE>
44
+ <Planning>
45
+ <l_plng_no>1</l_plng_no>
46
+ <l_imme_no>1</l_imme_no>
47
+ <l_lot_no>12</l_lot_no>
48
+ <l_ref>XXX</l_ref>
49
+ <o_debut>01/11/2016</o_debut>
50
+ <o_fin>01/12/2016</o_fin>
51
+ <o_type>YYY</o_type>
52
+ </Planning>
53
+ </LINE>
54
+ </QRY-CLT1XXX-TOP-1>}
55
+
56
+ VacationRentalsIcalAdapters::Parser.to_ical(arkiane_xml_body, source: source)
57
+ => """
58
+ BEGIN:VCALENDAR
59
+ VERSION:2.0
60
+ BEGIN:VEVENT
61
+ DTEND;VALUE=DATE:20161210
62
+ DTSTART;VALUE=DATE:20160827
63
+ END:VEVENT
64
+ BEGIN:VEVENT
65
+ DTEND;VALUE=DATE:20161201
66
+ DTSTART;VALUE=DATE:20161101
67
+ END:VEVENT
68
+ END:VCALENDAR
69
+ """
70
+ ```
71
+
72
+ ## Adding new adapters
73
+
74
+ Every new adapter needs to implement `applicable?(body:, source:)` and `to_ical(body)` methods. Once you've create a new adapter, you need to register it inside `VacationRentalsIcalAdapters::Adapters` class, for example:
75
+
76
+ ``` ruby
77
+ require "vacation_rentals_ical_adapters/adapters/new_awesome_adapter"
78
+
79
+ register(NewAwesomeAdapter.new)
80
+ ```
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Azdaroth/vacation_rentals_ical_adapters.
91
+
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
96
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vacation_rentals_ical_adapters"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "vacation_rentals_ical_adapters/version"
2
+ require "vacation_rentals_ical_adapters/parser"
3
+
4
+ module VacationRentalsIcalAdapters
5
+ end
@@ -0,0 +1,25 @@
1
+ require "vacation_rentals_ical_adapters/registry"
2
+
3
+ class VacationRentalsIcalAdapters::Adapters
4
+ def self.adapter_for(body:, source:)
5
+ registry.find_adapter do |adapter|
6
+ adapter.applicable?(body: body, source: source)
7
+ end
8
+ end
9
+
10
+ def self.registry
11
+ @registry ||= VacationRentalsIcalAdapters::Registry.new
12
+ end
13
+ private_class_method :registry
14
+
15
+ def self.register(adapter)
16
+ registry.register(adapter)
17
+ end
18
+ private_class_method :register
19
+
20
+ require "vacation_rentals_ical_adapters/adapters/ical_adapter"
21
+ require "vacation_rentals_ical_adapters/adapters/xml_arkiane_adapter"
22
+
23
+ register(IcalAdapter.new) # must be first
24
+ register(XmlArkianeAdapter.new)
25
+ end
@@ -0,0 +1,12 @@
1
+ require "vacation_rentals_ical_adapters/adapters"
2
+ require "icalendar"
3
+
4
+ class VacationRentalsIcalAdapters::Adapters::IcalAdapter
5
+ def applicable?(body:, source:)
6
+ Icalendar::Calendar.parse(body).any?
7
+ end
8
+
9
+ def to_ical(body)
10
+ body
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ require "active_support/core_ext/hash/conversions"
2
+ require "vacation_rentals_ical_adapters/event"
3
+ require "vacation_rentals_ical_adapters/ical_converter"
4
+
5
+ class VacationRentalsIcalAdapters::Adapters::XmlArkianeAdapter
6
+ ARKIANE_XML_HOST = "xml.arkiane.com".freeze
7
+ private_constant :ARKIANE_XML_HOST
8
+
9
+ def applicable?(body:, source:)
10
+ URI(source.to_s).host == ARKIANE_XML_HOST
11
+ end
12
+
13
+ def to_ical(body)
14
+ events = parse_events(body)
15
+ VacationRentalsIcalAdapters::IcalConverter.to_ical(events)
16
+ end
17
+
18
+ private
19
+
20
+ def parse_events(body)
21
+ extract_availabilities(body).map do |availability|
22
+ VacationRentalsIcalAdapters::Event.new(
23
+ start_date: availability.fetch("o_debut"),
24
+ end_date: availability.fetch("o_fin")
25
+ )
26
+ end
27
+ end
28
+
29
+ def extract_availabilities(body)
30
+ Hash.from_xml(body)
31
+ .to_a
32
+ .flatten
33
+ .last["LINE"]
34
+ .flat_map { |el| el["Planning"] }
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ class VacationRentalsIcalAdapters::Event
2
+ attr_reader :start_date, :end_date
3
+
4
+ def initialize(start_date:, end_date:)
5
+ @start_date = Date.parse(start_date)
6
+ @end_date = Date.parse(end_date)
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ class VacationRentalsIcalAdapters::IcalConverter
2
+ def self.to_ical(events)
3
+ new(events).to_ical
4
+ end
5
+
6
+ attr_reader :events
7
+ private :events
8
+
9
+ def initialize(events)
10
+ @events = events
11
+ end
12
+ private_class_method :new
13
+
14
+ def to_ical
15
+ [
16
+ ical_beginning,
17
+ events.map { |event| ical_event_from(event) },
18
+ ical_ending,
19
+ ].join("\n")
20
+ end
21
+
22
+ private
23
+
24
+ def ical_beginning
25
+ %Q{BEGIN:VCALENDAR
26
+ VERSION:2.0}
27
+ end
28
+
29
+ def ical_event_from(event)
30
+ %Q{BEGIN:VEVENT
31
+ DTEND;VALUE=DATE:#{format_date(event.end_date)}
32
+ DTSTART;VALUE=DATE:#{format_date(event.start_date)}
33
+ END:VEVENT}
34
+ end
35
+
36
+ def format_date(date)
37
+ date.strftime("%Y%m%d")
38
+ end
39
+
40
+ def ical_ending
41
+ %Q{END:VCALENDAR}
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ require "vacation_rentals_ical_adapters/adapters"
2
+
3
+ class VacationRentalsIcalAdapters::Parser
4
+ def self.to_ical(body, source:)
5
+ VacationRentalsIcalAdapters::Adapters
6
+ .adapter_for(body: body, source: source)
7
+ .to_ical(body)
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ class VacationRentalsIcalAdapters::Registry
2
+ attr_reader :adapters
3
+ private :adapters
4
+
5
+ def initialize
6
+ @adapters = []
7
+ end
8
+
9
+ def find_adapter(&block)
10
+ adapters.find(adapter_not_found_proc, &block)
11
+ end
12
+
13
+ def register(adapter)
14
+ adapters << adapter
15
+ end
16
+
17
+ private
18
+
19
+ def adapter_not_found_proc
20
+ -> { raise AdapterNotFoundError }
21
+ end
22
+
23
+ class AdapterNotFoundError < RuntimeError
24
+ def message
25
+ "Couldn't find adapter for given :body and :source, conversion to iCal format not possible."
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module VacationRentalsIcalAdapters
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vacation_rentals_ical_adapters/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vacation_rentals_ical_adapters"
8
+ spec.version = VacationRentalsIcalAdapters::VERSION
9
+ spec.authors = ["Karol Galanciak"]
10
+ spec.email = ["karol.galanciak@gmail.com"]
11
+
12
+ spec.summary = %q{Channel-based adapters for transforming input into iCal format}
13
+ spec.description = %q{Channel-based adapters for transforming input into iCal format}
14
+ spec.homepage = "http://github.com/Azdaroth/decent_presenter/vacation_rentals_ical_adapters"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "pry-byebug"
29
+ spec.add_development_dependency "coveralls"
30
+
31
+ spec.add_dependency "icalendar", "~> 2.4"
32
+ spec.add_dependency "activesupport", ">= 4.0"
33
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vacation_rentals_ical_adapters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Karol Galanciak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-04 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: icalendar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.4'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '4.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '4.0'
125
+ description: Channel-based adapters for transforming input into iCal format
126
+ email:
127
+ - karol.galanciak@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/vacation_rentals_ical_adapters.rb
143
+ - lib/vacation_rentals_ical_adapters/adapters.rb
144
+ - lib/vacation_rentals_ical_adapters/adapters/ical_adapter.rb
145
+ - lib/vacation_rentals_ical_adapters/adapters/xml_arkiane_adapter.rb
146
+ - lib/vacation_rentals_ical_adapters/event.rb
147
+ - lib/vacation_rentals_ical_adapters/ical_converter.rb
148
+ - lib/vacation_rentals_ical_adapters/parser.rb
149
+ - lib/vacation_rentals_ical_adapters/registry.rb
150
+ - lib/vacation_rentals_ical_adapters/version.rb
151
+ - vacation_rentals_ical_adapters.gemspec
152
+ homepage: http://github.com/Azdaroth/decent_presenter/vacation_rentals_ical_adapters
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.5.1
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Channel-based adapters for transforming input into iCal format
176
+ test_files: []