kiwi-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f728f24f6067242abe57048cd78abc0c060d701104f2a02bee572d5afc6d0b9
4
+ data.tar.gz: 4c7552a431c66b69680f2b0fdd4bdfe44a98ce2890467ef3aadc521db3ea2e6e
5
+ SHA512:
6
+ metadata.gz: 487ba98f52451aadbdd3ffdb465662691b9e0b1139b54ebd35d9ff54c26fc8a026ebecbd0dda22d16204bd5b472c2a51835cd325245ffccd2730eae8c412b07d
7
+ data.tar.gz: fe34df97aaa6b9d261497a674b5fbe58c4474ae232f08167a70a48b2ffcee2b6ff852b390e09b4a871c9a14152f55705cb1744585366cf7fb4540c73f93d8364
@@ -0,0 +1 @@
1
+ API_KEY=YOUR-API-KEY
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
@@ -0,0 +1,12 @@
1
+ FROM ruby:2.5.1
2
+ LABEL maintainer="estoy@moviendo.me"
3
+
4
+ ENV APP_HOME /app
5
+ RUN mkdir $APP_HOME
6
+ WORKDIR $APP_HOME
7
+
8
+ ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
9
+ BUNDLE_JOBS=8 \
10
+ BUNDLE_PATH=/bundle
11
+
12
+ CMD [".run.sh"]
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in kiwi.gemspec
6
+ gemspec
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kiwi-ruby (0.1.0)
5
+ activesupport
6
+ faraday
7
+ faraday_middleware
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.6.0)
18
+ public_suffix (>= 2.0.2, < 4.0)
19
+ concurrent-ruby (1.1.5)
20
+ crack (0.4.3)
21
+ safe_yaml (~> 1.0.0)
22
+ faraday (0.15.4)
23
+ multipart-post (>= 1.2, < 3)
24
+ faraday_middleware (0.13.1)
25
+ faraday (>= 0.7.4, < 1.0)
26
+ hashdiff (1.0.0)
27
+ i18n (1.6.0)
28
+ concurrent-ruby (~> 1.0)
29
+ minitest (5.11.3)
30
+ multipart-post (2.1.1)
31
+ public_suffix (3.1.1)
32
+ rake (10.5.0)
33
+ safe_yaml (1.0.5)
34
+ thread_safe (0.3.6)
35
+ tzinfo (1.2.5)
36
+ thread_safe (~> 0.1)
37
+ vcr (5.0.0)
38
+ webmock (3.6.2)
39
+ addressable (>= 2.3.6)
40
+ crack (>= 0.3.2)
41
+ hashdiff (>= 0.4.0, < 2.0.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.16)
48
+ kiwi-ruby!
49
+ minitest (~> 5.0)
50
+ rake (~> 10.0)
51
+ vcr
52
+ webmock (= 3.6.2)
53
+
54
+ BUNDLED WITH
55
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Jose Ferrer
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.
@@ -0,0 +1,84 @@
1
+ # Kiwi
2
+
3
+ [![Build Status](https://travis-ci.org/jferrer/kiwi.svg?branch=master)](https://travis-ci.org/jferrer/kiwi)
4
+
5
+ This is a Ruby wrapper for the [Tequila API](https://tequila.kiwi.com) ([Kiwi.com](https://www.kiwi.com)).
6
+
7
+ Currently only `search` and `location` are supported.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'kiwi-ruby'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install kiwi-ruby
24
+
25
+ ## Setup
26
+
27
+ Initialize the gem with a valid API KEY:
28
+
29
+ ```
30
+ KiwiApi.api_key = "your-api-key"
31
+ ```
32
+
33
+ ## Supported endpoints
34
+
35
+ ### search
36
+ Kiwi.com flights search API.
37
+
38
+ ```ruby
39
+ params = {
40
+ fly_from: "CNX",
41
+ fly_to: "BKK",
42
+ date_from: "10/10/2019",
43
+ date_to: "10/10/2019",
44
+ return_from: "14/10/2019",
45
+ return_to: "14/10/2019",
46
+ }
47
+
48
+ response = client.search(params)
49
+
50
+ response.success? # true/false
51
+
52
+ response.status # 200...
53
+
54
+ response.body # results...
55
+
56
+ response.errors # error message & full messages
57
+ ```
58
+
59
+ ### location
60
+ Locations is a simple API used to search, suggest and resolve locations in various situations.
61
+
62
+ ```ruby
63
+ params = {
64
+ term: "Chiang Mai"
65
+ }
66
+
67
+ response = client.location(params)
68
+
69
+ response.success? # true/false
70
+
71
+ response.status # 200...
72
+
73
+ response.body # results...
74
+
75
+ response.errors # error message & full messages
76
+ ```
77
+
78
+ ## Get Api Key
79
+
80
+ To get access to the Tequila API, signup as an affiliate [here](https://tequila.kiwi.com/portal/login/register).
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kiwi_api"
5
+
6
+ require "irb"
7
+ IRB.start(__FILE__)
@@ -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,14 @@
1
+ version: "3"
2
+ services:
3
+ app:
4
+ build: .
5
+ command: ./run.sh
6
+ tty: true
7
+ stdin_open: true
8
+ volumes:
9
+ - .:/app
10
+ - bundle_cache:/bundle
11
+ environment:
12
+ - API_KEY=${API_KEY}
13
+ volumes:
14
+ bundle_cache:
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "kiwi_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kiwi-ruby"
8
+ spec.version = KiwiApi::VERSION
9
+ spec.authors = ["Jose Ferrer"]
10
+ spec.email = ["estoy@moviendo.me"]
11
+
12
+ spec.summary = %q{Wrapper for the Kiwi.com API}
13
+ spec.homepage = "https://github.com/jferrer/kiwi"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "webmock", "3.6.2"
28
+ spec.add_dependency "faraday"
29
+ spec.add_dependency "faraday_middleware"
30
+ spec.add_dependency "activesupport"
31
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "json"
6
+ require "active_support/core_ext/hash"
7
+
8
+ require "kiwi_api/version"
9
+ require "kiwi_api/client"
10
+ require "kiwi_api/http_service"
11
+ require "kiwi_api/response"
12
+
13
+ module KiwiApi
14
+ class << self
15
+ attr_accessor :api_key
16
+ end
17
+
18
+ self.api_key = self.api_key || ENV["API_KEY"]
19
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiwiApi
4
+ class Client
5
+ def initialize
6
+ @http_service = HttpService.new
7
+ end
8
+
9
+ def http_service
10
+ @http_service
11
+ end
12
+
13
+ def search(params = {})
14
+ response = http_service.request_get("/v2/search", params)
15
+ KiwiApi::Response.new(response)
16
+ end
17
+
18
+ def location(params = {})
19
+ params.merge!(location_types: "airport")
20
+ response = http_service.request_get("/locations/query", params)
21
+ KiwiApi::Response.new(response)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiwiApi
4
+ class HttpService
5
+ def initialize
6
+ @api_key = KiwiApi.api_key
7
+ end
8
+
9
+ def connection
10
+ @connection ||= begin
11
+ Faraday.new(url: "https://kiwicom-prod.apigee.net") do |faraday|
12
+ faraday.adapter Faraday.default_adapter
13
+ faraday.headers["apikey"] = @api_key
14
+ end
15
+ end
16
+ end
17
+
18
+ def request_get(url, params)
19
+ connection.get do |req|
20
+ req.url url
21
+ req.params = params
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiwiApi
4
+ class Response
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def success?
10
+ true unless @response.status != 200
11
+ end
12
+
13
+ def status
14
+ @response.status
15
+ end
16
+
17
+ def body
18
+ JSON.parse(
19
+ JSON.parse(@response.body).deep_transform_keys { |key| key.to_s.underscore }.to_json,
20
+ object_class: OpenStruct
21
+ ) rescue nil
22
+ end
23
+
24
+ def errors
25
+ unless @response.success?
26
+ err = body
27
+
28
+ OpenStruct.new(
29
+ message: @response.reason_phrase,
30
+ full_messages: err.nil? ? nil : err.message
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiwiApi
4
+ VERSION = "0.1.0"
5
+ end
data/run.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+ bundle check || bundle install --jobs=8 --retry=3
3
+ bundle exec rake
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiwi-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jose Ferrer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-17 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
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: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.6.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.6.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
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: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - estoy@moviendo.me
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".env.sample.yml"
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - Dockerfile
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - docker-compose.yml
144
+ - kiwi.gemspec
145
+ - lib/kiwi_api.rb
146
+ - lib/kiwi_api/client.rb
147
+ - lib/kiwi_api/http_service.rb
148
+ - lib/kiwi_api/response.rb
149
+ - lib/kiwi_api/version.rb
150
+ - run.sh
151
+ homepage: https://github.com/jferrer/kiwi
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.7.7
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Wrapper for the Kiwi.com API
175
+ test_files: []