hailo 0.75

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: ef3f8ca4b68e4ed20e0386bbe19e51f24ef2dcb5
4
+ data.tar.gz: 4f30b7316855b47888a9c8191a66c702c0f4b23e
5
+ SHA512:
6
+ metadata.gz: a94f7601eb4fd74d924bce58e2d428724b78b1738de16c10d89f24400ece0b3faa288f246c0fe3c77692c86c2fc4ec3de8b08c0af638d16c229556d37ed6ce0b
7
+ data.tar.gz: 82be824b732d3e1eca51c3ddf9a9bba5e2cb6dc4cfccefe03808b59594e97d20bc2852054ca312dd1e30e4a5dfa841581fcb2f375fb425bf9c7fe8197128ea4a
@@ -0,0 +1,2 @@
1
+ sample-client.rb
2
+ .DS_Store
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Lukasz Raczylo
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,85 @@
1
+ # Gem for HAILO API ( hailocab.com )
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/hailo.svg)](http://badge.fury.io/rb/hailo)
4
+ [![Code Climate](https://codeclimate.com/github/lukaszraczylo/hailo-ruby/badges/gpa.svg)](https://codeclimate.com/github/lukaszraczylo/hailo-ruby)
5
+ [![Gratipay](https://img.shields.io/gratipay/lukaszraczylo.svg)](https://gratipay.com/lukaszraczylo/)
6
+
7
+ This is a Ruby Gem for the hailocab.com API. It should simplify the process of consuming data from the HAILO API for developers using Ruby.
8
+
9
+ ### Installation
10
+ Add following to your application Gemfile
11
+
12
+ ```
13
+ gem 'hailo'
14
+ ```
15
+
16
+ Then execute
17
+
18
+ ```
19
+ $ bundle install
20
+ ```
21
+
22
+ Or install it just like that
23
+
24
+ ```
25
+ $ gem install hailo
26
+ ```
27
+
28
+ ### Usage
29
+
30
+ It's pretty straightforward. Sample script using Hailo API:
31
+
32
+ ```
33
+ #!/usr/bin/env ruby
34
+ require 'hailo'
35
+ require 'ap'
36
+
37
+ CFG_USER_KEY = 'potatoKey'
38
+
39
+ client = Hailo::Client.new({ app_user_key: CFG_USER_KEY, api_host: 'https://api.hailoapp.com' })
40
+ result = client.drivers_near(:latitude => '51.512555', :longitude => '-0.127716')
41
+ ap result[0].service_type
42
+
43
+ result = client.drivers_eta(:latitude => '51.512555', :longitude => '-0.127716')
44
+ ap result
45
+ ```
46
+
47
+ Gives following output. JSON from return has been converted into object to make it easier to query.
48
+
49
+ ```
50
+ {
51
+ "drivers" => [
52
+ [0] {
53
+ "latitude" => 51.51025,
54
+ "longitude" => -0.1269102,
55
+ "service_type" => "regular"
56
+ },
57
+ [1] {
58
+ "latitude" => 51.512363,
59
+ "longitude" => -0.13302514,
60
+ "service_type" => "regular"
61
+ },
62
+ [2] {
63
+ "latitude" => 51.510216,
64
+ "longitude" => -0.117230095,
65
+ "service_type" => "regular"
66
+ },
67
+ [3] {
68
+ "latitude" => 51.516865,
69
+ "longitude" => -0.1368112,
70
+ "service_type" => "regular"
71
+ }
72
+ ]
73
+ }
74
+ {
75
+ "etas" => [
76
+ [0] {
77
+ "eta" => 5,
78
+ "count" => 4,
79
+ "service_type" => "regular"
80
+ }
81
+ ]
82
+ }
83
+ ```
84
+
85
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # Sample client for HAILO API gem
3
+
4
+ require 'hailo'
5
+ require 'ap'
6
+
7
+ CFG_USER_KEY = 'potatoKey'
8
+
9
+ client = Hailo::Client.new({ app_user_key: CFG_USER_KEY, api_host: 'https://api.hailoapp.com' })
10
+ result = client.drivers_near(:latitude => '51.512555', :longitude => '-0.127716')
11
+ ap result[0].service_type
12
+
13
+ result = client.drivers_eta(:latitude => '51.512555', :longitude => '-0.127716')
14
+ ap result
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hailo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hailo'
8
+ spec.version = Hailo::VERSION
9
+ spec.authors = ['Lukasz Raczylo']
10
+ spec.email = ['lukasz@raczylo.com']
11
+ spec.summary = %q{Ruby client library for hailocab.com API}
12
+ spec.description = 'Provides easy way to interact with the HAILO API in any kind of application'
13
+ spec.homepage = 'https://github.com/lukaszraczylo/hailo-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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
+ # Requirements
22
+ spec.required_ruby_version = '>=1.9.2'
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake', '~> 10.0', '>= 10.0.0'
25
+ spec.add_development_dependency 'rspec', '~> 2.6'
26
+ spec.add_development_dependency 'hashie', '~> 3.3'
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'hailo/version'
2
+ require 'hailo/client'
3
+
4
+ module Hailo
5
+ def self.client
6
+ @client ||= Hailo::Client.new
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ require 'hailo/configuration'
2
+ require 'awesome_print'
3
+ require 'httparty'
4
+
5
+ require 'hailo/operations/action'
6
+
7
+ module Hailo
8
+ class Client
9
+ REQUEST_CLASSES =[ Hailo::Operations::Action ]
10
+
11
+ attr_reader :configuration
12
+ attr_accessor :session
13
+
14
+ def initialize(options = nil)
15
+ @configuration = nil
16
+ define_request_methods
17
+
18
+ unless options.nil?
19
+ @configuration = Configuration.new(options)
20
+ check_api_keys
21
+ end
22
+ end
23
+
24
+ def check_api_keys
25
+ if configuration.nil? || !configuration.valid?
26
+ @configuration = nil
27
+ raise Error::NoApiKeys
28
+ else
29
+ @configuration.freeze
30
+ end
31
+ end
32
+
33
+ def define_request_methods
34
+ REQUEST_CLASSES.each do |request_class|
35
+ operations_instance = request_class.new(self)
36
+ create_methods_from_instance(operations_instance)
37
+ end
38
+ end
39
+
40
+ def create_methods_from_instance(instance)
41
+ instance.public_methods(false).each do |method_name|
42
+ add_method(instance, method_name)
43
+ end
44
+ end
45
+
46
+ def add_method(instance, method_name)
47
+ define_singleton_method(method_name) do |*args|
48
+ instance.public_send(method_name, *args)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ module Hailo
2
+ class Configuration
3
+ AUTH_KEYS = [:app_user_key, :api_host]
4
+ attr_accessor *AUTH_KEYS
5
+
6
+ def initialize(config_hash = nil)
7
+ if config_hash.is_a?(Hash)
8
+ config_hash.each do |config_name, config_value|
9
+ self.send("#{config_name}=", config_value)
10
+ end
11
+ end
12
+ end
13
+
14
+ # Returns a hash of api keys and their values
15
+ def auth_keys
16
+ AUTH_KEYS.inject({}) do |keys_hash, key|
17
+ keys_hash[key] = send(key)
18
+ keys_hash
19
+ end
20
+ end
21
+
22
+ def valid?
23
+ AUTH_KEYS.none? { |key| send(key).nil? || send(key).empty? }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ require 'open-uri'
2
+ require 'hashie'
3
+ require 'json'
4
+
5
+ module Hailo
6
+ module Operations
7
+ class Action
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def drivers_eta( p = {} )
13
+ param = { :api_url => "/drivers/eta" }
14
+ param = param.merge(p)
15
+ @client.session = login_request(param)
16
+
17
+ end
18
+
19
+ def drivers_near( p = {} )
20
+ param = { :api_url => "/drivers/near" }
21
+ param = param.merge(p)
22
+ @client.session = login_request(param)
23
+ end
24
+
25
+ private
26
+ def login_request( p = {} )
27
+ # ap @client.configuration.app_user_key
28
+ if p[:api_url].nil?; p[:api_url] = ''; end
29
+ q_headers = { "Authorization" => @client.configuration.app_user_key }
30
+ q_request = Hash.new
31
+ q_url = "#{@client.configuration.api_host}#{p[:api_url]}"
32
+ p.delete(:api_url)
33
+ p[:api_token] = URI::encode(@client.configuration.app_user_key)
34
+ q_request = p
35
+ @options = { :query => q_request, :headers => q_headers }
36
+ obj = HTTParty.get(q_url.to_s, @options).to_json
37
+ result = JSON.parse(obj)
38
+ obj = Hashie::Mash.new(result)
39
+ return obj
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Hailo
2
+ VERSION = "0.75"
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hailo
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.75'
5
+ platform: ruby
6
+ authors:
7
+ - Lukasz Raczylo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-08 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: '10.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 10.0.0
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: hashie
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.3'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.3'
75
+ description: Provides easy way to interact with the HAILO API in any kind of application
76
+ email:
77
+ - lukasz@raczylo.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - LICENSE
84
+ - README.md
85
+ - example-client.rb
86
+ - hailo.gemspec
87
+ - lib/hailo.rb
88
+ - lib/hailo/client.rb
89
+ - lib/hailo/configuration.rb
90
+ - lib/hailo/operations/action.rb
91
+ - lib/hailo/version.rb
92
+ homepage: https://github.com/lukaszraczylo/hailo-ruby
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 1.9.2
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Ruby client library for hailocab.com API
116
+ test_files: []