london_cab-auth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4bd80a0d4e03ab8c0fa7ad0c5de43b735af643d
4
+ data.tar.gz: 346d082ece7dbf7c1bc76f599f75a9407a99314b
5
+ SHA512:
6
+ metadata.gz: 640c871270bfda03d30d1a13cf9aa165e00b943405aae270c3d45be934df48758d5a4f71904c1df8efd62a1d83f2c15f3702ff743f80b60225e0eff18872bd21
7
+ data.tar.gz: ef3a0648ddd7541ead18353d52bac9c769fdcf6712d4b31e42087c94d89cb0c77d77c920d075fb7663de90a29a5c43bca263d216b56c6761ddb32fc13747ae9e
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ Lint/HandleExceptions:
2
+ Enabled: false
3
+
4
+ Metrics/AbcSize:
5
+ Max: 25
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ Metrics/MethodLength:
11
+ Max: 25
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Style/FileName:
17
+ Exclude:
18
+ - 'lib/london_cab-auth.rb'
19
+
20
+ Style/ModuleFunction:
21
+ Enabled: false
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.14.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in london_cab.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # LondonCab
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/london_cab-auth.svg)](http://badge.fury.io/rb/london_cab-auth)
4
+ [![Build Status](https://travis-ci.org/RaMin0/london_cab-auth.svg?branch=master)](https://travis-ci.org/RaMin0/london_cab-auth)
5
+ [![Code Climate](https://codeclimate.com/github/RaMin0/london_cab-auth/badges/gpa.svg)](https://codeclimate.com/github/RaMin0/london_cab-auth)
6
+
7
+ An authentication extension for [london_cab](https://github.com/RaMin0/london_cab).
8
+
9
+ [![](london_cab.png)](http://65.182.108.16)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'london_cab-auth'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```
22
+ $ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```
28
+ $ gem install london_cab-auth
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### API Token
34
+ To acquire an API token, use the same credentials for your corporate London Cab account.
35
+
36
+ ### Configuration
37
+
38
+ ```ruby
39
+ LondonCab::Auth.configure do |config|
40
+ config.username = ENV['LONDON_CAB_API_AUTH_USERNAME']
41
+ config.password = ENV['LONDON_CAB_API_AUTH_PASSWORD']
42
+ end
43
+ ```
44
+
45
+ This sets a global default username and password. You can also pass a username and password to the initializer of `LondonCab::Auth::Client`.
46
+
47
+ ```ruby
48
+ client = LondonCab::Auth::Client.new(username: ENV['LONDON_CAB_API_AUTH_USERNAME'],
49
+ password: ENV['LONDON_CAB_API_AUTH_PASSWORD'])
50
+ ```
51
+
52
+ The instance username and password will be used over the global default.
53
+
54
+ The following globals settings are supported via `LondonCab::Auth.configure`.
55
+
56
+ setting | description
57
+ -------------|------------
58
+ username | London Cab API Auth username.
59
+ password | London Cab API Auth password.
60
+ logger | An optional logger.<br/>**Default:** `Logger.new(STDOUT)` at `Logger::WARN` level.
61
+
62
+ ### Client
63
+
64
+ The London Cab Auth allows you to generate tokens that can be used with the London Cab API client.
65
+
66
+ #### Configuration
67
+ setting | description
68
+ -------------|------------
69
+ endpoint | London Cab Auth endpoint.<br/>**Default:** http://65.182.108.16:22710
70
+ user_agent | User-agent.<br/>**Default:** LondonCab::Auth/VERSION.
71
+ username | **Required.** London Cab API Auth username.
72
+ password | **Required.** London Cab API Auth password.
73
+ logger | **Optional.** `Logger` instance that logs HTTP requests.
74
+
75
+ ## Documentation
76
+
77
+ ### Auth
78
+ You can use the client to make requests related to auth.
79
+
80
+ #### Generate Auth
81
+
82
+ Request rides with `#auth`.
83
+
84
+ ```ruby
85
+ client.auth
86
+ ```
87
+
88
+ ## History
89
+
90
+ The structure of this gem is based on [slack-ruby-client](https://github.com/slack-ruby/slack-ruby-client).
91
+
92
+ ## Development
93
+
94
+ 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.
95
+
96
+ 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).
97
+
98
+ ## Contributing
99
+
100
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/RaMin0/london_cab-auth]().
101
+
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 'london_cab-auth'
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(__FILE__)
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 @@
1
+ require 'london_cab_auth'
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'byebug'
3
+ rescue LoadError
4
+ end
5
+
6
+ require 'london_cab_auth/version'
7
+ require 'london_cab_auth/logger'
8
+ require 'london_cab_auth/config'
9
+
10
+ # API
11
+ require 'faraday'
12
+ require 'faraday_middleware'
13
+ require 'json'
14
+ require 'logger'
15
+
16
+ require 'london_cab_auth/api/error'
17
+ require 'london_cab_auth/faraday/connection'
18
+ require 'london_cab_auth/faraday/request'
19
+ require 'london_cab_auth/api/endpoints'
20
+ require 'london_cab_auth/client'
@@ -0,0 +1,11 @@
1
+ require 'london_cab_auth/api/endpoints/auth'
2
+
3
+ module LondonCab
4
+ module Auth
5
+ module Api
6
+ module Endpoints
7
+ include Auth
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module LondonCab
2
+ module Auth
3
+ module Api
4
+ module Endpoints
5
+ module Auth
6
+ def auth(options = {})
7
+ options = { username: username,
8
+ password: password,
9
+ grant_type: :password,
10
+ client_id: 'AGMIdentityServer',
11
+ client_secret: 'secret',
12
+ scope: 'read' }.merge(options)
13
+ post('Connect/Token', options)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module LondonCab
2
+ module Auth
3
+ module Api
4
+ class Error < ::Faraday::Error
5
+ attr_reader :response
6
+
7
+ def initialize(message, response = nil)
8
+ @response = response
9
+ super(message)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ module LondonCab
2
+ module Auth
3
+ class Client
4
+ include Faraday::Connection
5
+ include Faraday::Request
6
+ include Api::Endpoints
7
+
8
+ attr_accessor(*Config::ATTRIBUTES)
9
+
10
+ def initialize(options = {})
11
+ LondonCab::Auth::Config::ATTRIBUTES.each do |key|
12
+ send("#{key}=", options[key] || LondonCab::Auth.config.send(key))
13
+ end
14
+
15
+ @logger ||= LondonCab::Auth::Config.logger || LondonCab::Auth::Logger.default
16
+ end
17
+
18
+ class << self
19
+ def configure
20
+ block_given? ? yield(Config) : Config
21
+ end
22
+
23
+ def config
24
+ Config
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ module LondonCab
2
+ module Auth
3
+ module Config
4
+ extend self
5
+
6
+ ATTRIBUTES = [
7
+ :endpoint,
8
+ :user_agent,
9
+ :username,
10
+ :password,
11
+ :logger
12
+ ].freeze
13
+
14
+ attr_accessor(*Config::ATTRIBUTES)
15
+
16
+ def reset
17
+ self.endpoint = 'http://65.182.108.16:22710'
18
+ self.user_agent = "LondonCab::Auth/#{LondonCab::Auth::VERSION}"
19
+ self.username = nil
20
+ self.password = nil
21
+ self.logger = nil
22
+ end
23
+
24
+ reset
25
+ end
26
+
27
+ class << self
28
+ def configure
29
+ block_given? ? yield(Config) : Config
30
+ end
31
+
32
+ def config
33
+ Config
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ module LondonCab
2
+ module Auth
3
+ module Faraday
4
+ module Connection
5
+ private
6
+
7
+ def connection
8
+ options = { headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } }
9
+
10
+ options[:headers]['User-Agent'] = user_agent if user_agent
11
+
12
+ ::Faraday::Connection.new(endpoint, options) do |connection|
13
+ connection.use ::Faraday::Request::UrlEncoded
14
+ connection.use ::FaradayMiddleware::ParseJson
15
+ connection.use ::Faraday::Response::RaiseError
16
+
17
+ connection.response :logger, logger if logger
18
+ connection.adapter ::Faraday.default_adapter
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ module LondonCab
2
+ module Auth
3
+ module Faraday
4
+ module Request
5
+ def get(path, options = {})
6
+ request(:get, path, options)
7
+ end
8
+
9
+ def post(path, options = {})
10
+ request(:post, path, options)
11
+ end
12
+
13
+ def put(path, options = {})
14
+ request(:put, path, options)
15
+ end
16
+
17
+ def delete(path, options = {})
18
+ request(:delete, path, options)
19
+ end
20
+
21
+ private
22
+
23
+ def request(method, path, options)
24
+ response = connection.send(method) do |request|
25
+ case method
26
+ when :get, :delete
27
+ request.url(path, options)
28
+ when :post, :put
29
+ request.path = path
30
+ request.body = options unless options.empty?
31
+ end
32
+ end
33
+ response.body
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ require 'logger'
2
+
3
+ module LondonCab
4
+ module Auth
5
+ class Logger < ::Logger
6
+ def self.default
7
+ @logger ||= begin
8
+ logger = new STDOUT
9
+ logger.progname = "LondonCab::Auth/#{VERSION}"
10
+ logger.level = Logger::WARN
11
+ logger
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module LondonCab
2
+ module Auth
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'london_cab_auth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'london_cab-auth'
8
+ spec.version = LondonCab::Auth::VERSION
9
+ spec.authors = ['Ramy Aboul Naga']
10
+ spec.email = ['ramy.naga@gmail.com']
11
+
12
+ spec.summary = 'LondonCab Authentication Client'
13
+ spec.homepage = 'https://github.com/RaMin0/london_cab-auth'
14
+
15
+ spec.files = `git ls-files`.split("\n").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'faraday', '>= 0.9'
21
+ spec.add_dependency 'faraday_middleware'
22
+ spec.add_dependency 'json'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.14'
25
+ spec.add_development_dependency 'byebug', '~> 9.0'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.47.1'
29
+ end
data/london_cab.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: london_cab-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ramy Aboul Naga
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '9.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '9.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.47.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.47.1
125
+ description:
126
+ email:
127
+ - ramy.naga@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/london_cab-auth.rb
142
+ - lib/london_cab_auth.rb
143
+ - lib/london_cab_auth/api/endpoints.rb
144
+ - lib/london_cab_auth/api/endpoints/auth.rb
145
+ - lib/london_cab_auth/api/error.rb
146
+ - lib/london_cab_auth/client.rb
147
+ - lib/london_cab_auth/config.rb
148
+ - lib/london_cab_auth/faraday/connection.rb
149
+ - lib/london_cab_auth/faraday/request.rb
150
+ - lib/london_cab_auth/logger.rb
151
+ - lib/london_cab_auth/version.rb
152
+ - london_cab-auth.gemspec
153
+ - london_cab.png
154
+ homepage: https://github.com/RaMin0/london_cab-auth
155
+ licenses: []
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.6.8
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: LondonCab Authentication Client
177
+ test_files: []