yt-auth 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eae916ff8a0b31773c93ae830d2d151c894724af
4
- data.tar.gz: 8143530fa4e8b21f3457fc411602e55d4d13ddd5
3
+ metadata.gz: f0c8b8b1fb86567a1fac8a9f824c02df621588c0
4
+ data.tar.gz: bef00004294f1b4f60dfc14c4f47821cd632bdf9
5
5
  SHA512:
6
- metadata.gz: a0e6e06cc458c1ec49e1e17fdf86bbe76f37982e4b875ac0e6dc2c7325a94116186512f09a2a2ddf05f2a74f1d00f10444a3fbaf5f69a4e9783298df10edd28a
7
- data.tar.gz: 41678fd22b58200a537f4a7c9461b61dd3d6f2fc1180644afc59b7f38610fe7015d37f0c580d3300a940737d937cf0bb923f769e87ab2ec8427769f0dc7e258f
6
+ metadata.gz: 58ddb25205d859933ac217a9250806fa63a6de154710dde3984b4cf011f599631d3e5550bcc28a5909f472f197f984095d7cfce858ab061d8deef1308682080d
7
+ data.tar.gz: 02444caa168eddd2ca09218690b024baf76f67c6ab675cae7b91269ee4fb1ebd1cf14dd30b6559e19ffd8b79114b682c8cd4af61c207e13960af55ddeb064f27
data/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.2.0 - 2017-03-29
10
+
11
+ **How to upgrade**
12
+
13
+ If your code uses `Yt::AuthError` then you must use `Yt::HTTPError` instead.
14
+ If your code uses `Yt::AuthRequest` then you must use `Yt::HTTPRequest` instead.
15
+
16
+ * [ENHANCEMENT] Extract `AuthError` to `HTTPError` in yt-support gem
17
+ * [ENHANCEMENT] Extract `AuthRequest` to `HTTPRequest` in yt-support gem
18
+
9
19
  ## 0.1.0 - 2017-03-27
10
20
 
11
21
  * [FEATURE] Add `AuthError`
data/README.md CHANGED
@@ -12,7 +12,7 @@ The **source code** is available on [GitHub](https://github.com/fullscreen/yt-au
12
12
  [![Online docs](http://img.shields.io/badge/docs-✓-green.svg)](http://www.rubydoc.info/gems/yt-auth/frames)
13
13
  [![Gem Version](http://img.shields.io/gem/v/yt-auth.svg)](http://rubygems.org/gems/yt-auth)
14
14
 
15
- The Yt::Auth library provides two methods: `url` and `email`.
15
+ The Yt::Auth class provides two public methods: `url` and `email`.
16
16
 
17
17
  Yt::Auth#url
18
18
  ------------
@@ -42,17 +42,17 @@ Yt::Auth.new(redirect_uri: redirect_uri, code: code).email
42
42
  # => "user@example.com"
43
43
  ```
44
44
 
45
- Yt::AuthError
45
+ Yt::HTTPError
46
46
  -------------
47
47
 
48
- `Yt::AuthError` will be raised whenever something goes wrong during the
48
+ `Yt::HTTPError` will be raised whenever something goes wrong during the
49
49
  authentication process. The message of the error will include the details:
50
50
 
51
51
  ```ruby
52
52
  redirect_uri = 'https://example.com/auth' # REPLACE WITH REAL ONE
53
53
  code = 'this-is-not-a-valid-code'
54
54
  Yt::Auth.new(redirect_uri: redirect_uri, code: code).email
55
- # => Yt::AuthError: Invalid authorization code.
55
+ # => Yt::HTTPError: Invalid authorization code.
56
56
  ```
57
57
 
58
58
 
data/lib/yt/auth.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'yt/config'
2
- require 'yt/auth_request'
2
+ require 'yt/http_request'
3
3
 
4
4
  # An object-oriented Ruby client for YouTube.
5
5
  # @see http://www.rubydoc.info/gems/yt/
@@ -27,7 +27,7 @@ module Yt
27
27
 
28
28
  # @return [String] the email of an authenticated Google account.
29
29
  def email
30
- response = AuthRequest.new(email_params).run
30
+ response = HTTPRequest.new(email_params).run
31
31
  response.body['email']
32
32
  end
33
33
 
@@ -51,7 +51,7 @@ module Yt
51
51
 
52
52
  # @return [Hash] the tokens of an authenticated Google account.
53
53
  def tokens
54
- AuthRequest.new(tokens_params).run.body
54
+ HTTPRequest.new(tokens_params).run.body
55
55
  end
56
56
 
57
57
  def tokens_params
@@ -1,6 +1,6 @@
1
1
  module Yt
2
2
  class Auth
3
3
  # current version of gem
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
data/yt-auth.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'yt-support', '>= 0.1'
25
+ spec.add_dependency 'yt-support', '>= 0.1.1'
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 1.14'
28
28
  spec.add_development_dependency 'rspec', '~> 3.5'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-03-27 00:00:00.000000000 Z
12
+ date: 2017-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yt-support
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '0.1'
20
+ version: 0.1.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '0.1'
27
+ version: 0.1.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -131,8 +131,6 @@ files:
131
131
  - bin/setup
132
132
  - lib/yt/auth.rb
133
133
  - lib/yt/auth/version.rb
134
- - lib/yt/auth_error.rb
135
- - lib/yt/auth_request.rb
136
134
  - yt-auth.gemspec
137
135
  homepage: https://github.com/fullscreen/yt-auth
138
136
  licenses:
data/lib/yt/auth_error.rb DELETED
@@ -1,5 +0,0 @@
1
- module Yt
2
- # A wrapper around StandardError.
3
- class AuthError < StandardError
4
- end
5
- end
@@ -1,91 +0,0 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'yt/auth_error'
4
-
5
- module Yt
6
- # @private
7
- # A wrapper around Net::HTTP to send HTTP requests to any web API and
8
- # return their result or raise an error if the result is unexpected.
9
- class AuthRequest
10
- # Initializes an AuthRequest object.
11
- def initialize(options = {})
12
- @host = options.fetch :host, 'www.googleapis.com'
13
- @path = options[:path]
14
- @method = options.fetch :method, :get
15
- @headers = options.fetch :headers, {}
16
- @body = options[:body]
17
- @request_format = options.fetch :request_format, :json
18
- @error_message = options.fetch :error_message, ->(body) {"Error: #{body}"}
19
- end
20
-
21
- # Sends the request and returns the response.
22
- def run
23
- if response.is_a? Net::HTTPSuccess
24
- response.tap do
25
- parse_response!
26
- end
27
- else
28
- raise Yt::AuthError, error_message
29
- end
30
- end
31
-
32
- private
33
-
34
- # @return [URI::HTTPS] the (memoized) URI of the request.
35
- def uri
36
- attributes = {host: @host, path: @path}
37
- @uri ||= URI::HTTPS.build attributes
38
- end
39
-
40
- # @return [Net::HTTPRequest] the full HTTP request object,
41
- # inclusive of headers of request body.
42
- def http_request
43
- net_http_class = Object.const_get "Net::HTTP::#{@method.capitalize}"
44
- @http_request ||= net_http_class.new(uri.request_uri).tap do |request|
45
- set_request_body! request
46
- set_request_headers! request
47
- end
48
- end
49
-
50
- # Adds the request body to the request in the appropriate format.
51
- # if the request body is a JSON Object, transform its keys into camel-case,
52
- # since this is the common format for JSON APIs.
53
- def set_request_body!(request)
54
- if @body
55
- request.set_form_data @body
56
- end
57
- end
58
-
59
- # Adds the request headers to the request in the appropriate format.
60
- # The User-Agent header is also set to recognize the request, and to
61
- # tell the server that gzip compression can be used, since Net::HTTP
62
- # supports it and automatically sets the Accept-Encoding header.
63
- def set_request_headers!(request)
64
- if @request_format == :json
65
- request.initialize_http_header 'Content-Type' => 'application/json'
66
- end
67
- @headers.each do |name, value|
68
- request.add_field name, value
69
- end
70
- end
71
-
72
- # Run the request and memoize the response or the server error received.
73
- def response
74
- @response ||= Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
75
- http.request http_request
76
- end
77
- end
78
-
79
- # Replaces the body of the response with the parsed version of the body,
80
- # according to the format specified in the AuthRequest.
81
- def parse_response!
82
- if response.body
83
- response.body = JSON response.body
84
- end
85
- end
86
-
87
- def error_message
88
- @error_message.call response.body
89
- end
90
- end
91
- end