-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3ce7eac
Showing
28 changed files
with
3,128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
API_KEY=YOUR-API-KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
sudo: false | ||
language: ruby | ||
cache: bundler | ||
rvm: | ||
- 2.5.1 | ||
before_install: gem install bundler -v 1.16.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ruby:2.5.1 | ||
LABEL maintainer="estoy@moviendo.me" | ||
|
||
ENV APP_HOME /app | ||
RUN mkdir $APP_HOME | ||
WORKDIR $APP_HOME | ||
|
||
ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \ | ||
BUNDLE_JOBS=8 \ | ||
BUNDLE_PATH=/bundle | ||
|
||
CMD [".run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source "https://rubygems.org" | ||
|
||
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | ||
|
||
# Specify your gem's dependencies in kiwi.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
kiwi-ruby (0.1.0) | ||
activesupport | ||
faraday | ||
faraday_middleware | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (5.2.3) | ||
concurrent-ruby (~> 1.0, >= 1.0.2) | ||
i18n (>= 0.7, < 2) | ||
minitest (~> 5.1) | ||
tzinfo (~> 1.1) | ||
addressable (2.6.0) | ||
public_suffix (>= 2.0.2, < 4.0) | ||
concurrent-ruby (1.1.5) | ||
crack (0.4.3) | ||
safe_yaml (~> 1.0.0) | ||
faraday (0.15.4) | ||
multipart-post (>= 1.2, < 3) | ||
faraday_middleware (0.13.1) | ||
faraday (>= 0.7.4, < 1.0) | ||
hashdiff (1.0.0) | ||
i18n (1.6.0) | ||
concurrent-ruby (~> 1.0) | ||
minitest (5.11.3) | ||
multipart-post (2.1.1) | ||
public_suffix (3.1.1) | ||
rake (10.5.0) | ||
safe_yaml (1.0.5) | ||
thread_safe (0.3.6) | ||
tzinfo (1.2.5) | ||
thread_safe (~> 0.1) | ||
vcr (5.0.0) | ||
webmock (3.6.2) | ||
addressable (>= 2.3.6) | ||
crack (>= 0.3.2) | ||
hashdiff (>= 0.4.0, < 2.0.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (~> 1.16) | ||
kiwi-ruby! | ||
minitest (~> 5.0) | ||
rake (~> 10.0) | ||
vcr | ||
webmock (= 3.6.2) | ||
|
||
BUNDLED WITH | ||
1.16.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Jose Ferrer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Kiwi | ||
|
||
[](https://travis-ci.org/jferrer/kiwi) [](https://badge.fury.io/rb/kiwi-ruby) | ||
|
||
This is a Ruby wrapper for the [Tequila API](https://tequila.kiwi.com) ([Kiwi.com](https://www.kiwi.com)). | ||
|
||
Currently only `search` and `location` are supported. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'kiwi-ruby' | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install kiwi-ruby | ||
|
||
## Setup | ||
|
||
Initialize the gem with a valid API KEY: | ||
|
||
``` | ||
KiwiApi.api_key = "your-api-key" | ||
``` | ||
|
||
## Supported endpoints | ||
|
||
### search | ||
Kiwi.com flights search API. | ||
|
||
```ruby | ||
params = { | ||
fly_from: "CNX", | ||
fly_to: "BKK", | ||
date_from: "10/10/2019", | ||
date_to: "10/10/2019", | ||
return_from: "14/10/2019", | ||
return_to: "14/10/2019", | ||
} | ||
|
||
response = client.search(params) | ||
|
||
response.success? # true/false | ||
|
||
response.status # 200... | ||
|
||
response.body # results... | ||
|
||
response.errors # error message & full messages | ||
``` | ||
|
||
### location | ||
Locations is a simple API used to search, suggest and resolve locations in various situations. | ||
|
||
```ruby | ||
params = { | ||
term: "Chiang Mai" | ||
} | ||
|
||
response = client.location(params) | ||
|
||
response.success? # true/false | ||
|
||
response.status # 200... | ||
|
||
response.body # results... | ||
|
||
response.errors # error message & full messages | ||
``` | ||
|
||
## Get Api Key | ||
|
||
To get access to the Tequila API, signup as an affiliate [here](https://tequila.kiwi.com/portal/login/register). | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "bundler/gem_tasks" | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
t.libs << "test" | ||
t.libs << "lib" | ||
t.test_files = FileList["test/**/*_test.rb"] | ||
end | ||
|
||
task :default => :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "bundler/setup" | ||
require "kiwi_api" | ||
|
||
require "irb" | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: "3" | ||
services: | ||
app: | ||
build: . | ||
command: ./run.sh | ||
tty: true | ||
stdin_open: true | ||
volumes: | ||
- .:/app | ||
- bundle_cache:/bundle | ||
environment: | ||
- API_KEY=${API_KEY} | ||
volumes: | ||
bundle_cache: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
lib = File.expand_path("../lib", __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require "kiwi_api/version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "kiwi-ruby" | ||
spec.version = KiwiApi::VERSION | ||
spec.authors = ["Jose Ferrer"] | ||
spec.email = ["estoy@moviendo.me"] | ||
|
||
spec.summary = %q{Wrapper for the Kiwi.com API} | ||
spec.homepage = "https://github.com/jferrer/kiwi" | ||
spec.license = "MIT" | ||
|
||
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do | ||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
end | ||
spec.bindir = "exe" | ||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency "bundler", "~> 1.16" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
spec.add_development_dependency "minitest", "~> 5.0" | ||
spec.add_development_dependency "vcr" | ||
spec.add_development_dependency "webmock", "3.6.2" | ||
spec.add_dependency "faraday" | ||
spec.add_dependency "faraday_middleware" | ||
spec.add_dependency "activesupport" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "faraday" | ||
require "faraday_middleware" | ||
require "json" | ||
require "active_support/core_ext/hash" | ||
|
||
require "kiwi_api/version" | ||
require "kiwi_api/client" | ||
require "kiwi_api/http_service" | ||
require "kiwi_api/response" | ||
|
||
module KiwiApi | ||
class << self | ||
attr_accessor :api_key | ||
end | ||
|
||
self.api_key = self.api_key || ENV["API_KEY"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module KiwiApi | ||
class Client | ||
def initialize | ||
@http_service = HttpService.new | ||
end | ||
|
||
def http_service | ||
@http_service | ||
end | ||
|
||
def search(params = {}) | ||
response = http_service.request_get("/v2/search", params) | ||
KiwiApi::Response.new(response) | ||
end | ||
|
||
def location(params = {}) | ||
params.merge!(location_types: "airport") | ||
response = http_service.request_get("/locations/query", params) | ||
KiwiApi::Response.new(response) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module KiwiApi | ||
class HttpService | ||
def initialize | ||
@api_key = KiwiApi.api_key | ||
end | ||
|
||
def connection | ||
@connection ||= begin | ||
Faraday.new(url: "https://kiwicom-prod.apigee.net") do |faraday| | ||
faraday.adapter Faraday.default_adapter | ||
faraday.headers["apikey"] = @api_key | ||
end | ||
end | ||
end | ||
|
||
def request_get(url, params) | ||
connection.get do |req| | ||
req.url url | ||
req.params = params | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module KiwiApi | ||
class Response | ||
def initialize(response) | ||
@response = response | ||
end | ||
|
||
def success? | ||
true unless @response.status != 200 | ||
end | ||
|
||
def status | ||
@response.status | ||
end | ||
|
||
def body | ||
JSON.parse( | ||
JSON.parse(@response.body).deep_transform_keys { |key| key.to_s.underscore }.to_json, | ||
object_class: OpenStruct | ||
) rescue nil | ||
end | ||
|
||
def errors | ||
unless @response.success? | ||
err = body | ||
|
||
OpenStruct.new( | ||
message: @response.reason_phrase, | ||
full_messages: err.nil? ? nil : err.message | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module KiwiApi | ||
VERSION = "0.1.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
bundle check || bundle install --jobs=8 --retry=3 | ||
bundle exec rake |
Oops, something went wrong.