safie 0.0.2 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c322e6bbb628507a172dcfc47d18d0b0a235e5360cd3e2437a78f931548c67a2
4
- data.tar.gz: bc16514d4641816bb8d09c36de3a148fe4878fbdd843479094fbd7df692fb103
3
+ metadata.gz: 76986f81ae83e04ed006e9df4d27c6d29c41bf368e11906338aa90d4a31854a9
4
+ data.tar.gz: 3a29d0eb9d29e06e624e6d7870f9e2f66f637ff43df9fcf9854cd1e819ac07a0
5
5
  SHA512:
6
- metadata.gz: 8368d23b5456a5c98227bcc53e9bf40be9141916229671021348e700cb07e80abab1c4243919f7ceca10ae83ea63ac77e5c87546a28ec16890f1ea446780e777
7
- data.tar.gz: 659cb03e5750197c76d7f7e65e948c4626a86567a188919cac430e60b7e75c93fa428a555aace554b8952ffa0e00cdd12ee170a892f6122be3cc063d96504348
6
+ metadata.gz: 1cb5418f73a157d9da09905fdccd235c067ec97ee0d32be68df5ee4eb0975204f8ae1a5aaa7b6c687a2c3976f87fe5037a19f730aee57fe015a493f13b7c373b
7
+ data.tar.gz: e088cd677feb04ed1478d9cf31861b582ecb2b93bb4cd5e631d98336fb2c44b627b1091ef7d2f04a107c0e4d1b44e92568fd3e1f6b42eedfd8acd26fc7855b4d
data/README.md CHANGED
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
32
 
33
33
  ## Contributing
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/safie.
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nov/safie.
36
36
 
37
37
  ## License
38
38
 
data/Rakefile CHANGED
@@ -1,6 +1,19 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
3
 
4
+ require 'rspec/core/rake_task'
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
7
+ namespace :coverage do
8
+ desc 'Open coverage report'
9
+ task :report do
10
+ require 'simplecov'
11
+ `open "#{File.join SimpleCov.coverage_path, 'index.html'}"`
12
+ end
13
+ end
14
+
15
+ task :spec do
16
+ Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
17
+ end
18
+
6
19
  task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -8,7 +8,7 @@ module Safie
8
8
 
9
9
  def token_info!(params = {})
10
10
  resource_request do
11
- get File.join(ISSUER, '/auth/tokeninfo'), params
11
+ get ENDPOINTS[:token_info], params
12
12
  end
13
13
  end
14
14
 
data/lib/safie/client.rb CHANGED
@@ -4,8 +4,8 @@ module Safie
4
4
 
5
5
  def initialize(attributes)
6
6
  attributes_with_default = {
7
- authorization_endpoint: File.join(ISSUER, '/auth/authorize'),
8
- token_endpoint: File.join(ISSUER, '/auth/token')
7
+ authorization_endpoint: ENDPOINTS[:authorization],
8
+ token_endpoint: ENDPOINTS[:token]
9
9
  }.merge(attributes)
10
10
  super attributes_with_default
11
11
  end
@@ -0,0 +1,39 @@
1
+ module Safie
2
+ class Exception < StandardError; end
3
+
4
+ class ValidationFailed < Exception
5
+ attr_reader :object
6
+
7
+ def initialize(object)
8
+ super object.errors.full_messages.to_sentence
9
+ @object = object
10
+ end
11
+ end
12
+
13
+ class HttpError < Exception
14
+ attr_accessor :status, :response
15
+ def initialize(status, message = nil, response = nil)
16
+ super message
17
+ @status = status
18
+ @response = response
19
+ end
20
+ end
21
+
22
+ class BadRequest < HttpError
23
+ def initialize(message = nil, response = nil)
24
+ super 400, message, response
25
+ end
26
+ end
27
+
28
+ class Unauthorized < HttpError
29
+ def initialize(message = nil, response = nil)
30
+ super 401, message, response
31
+ end
32
+ end
33
+
34
+ class Forbidden < HttpError
35
+ def initialize(message = nil, response = nil)
36
+ super 403, message, response
37
+ end
38
+ end
39
+ end
data/lib/safie.rb CHANGED
@@ -3,8 +3,13 @@ require 'rack/oauth2'
3
3
  module Safie
4
4
  ISSUER = 'https://app.safie.link'
5
5
  DEFAULT_SCOPE = :use
6
- VERSION = ::File.read(
7
- ::File.join(::File.dirname(__FILE__), '../VERSION')
6
+ ENDPOINTS = {
7
+ authorization: File.join(ISSUER, '/auth/authorize'),
8
+ token: File.join(ISSUER, '/auth/token'),
9
+ token_info: File.join(ISSUER, '/auth/tokeninfo')
10
+ }
11
+ VERSION = File.read(
12
+ File.join(File.dirname(__FILE__), '../VERSION')
8
13
  ).chomp
9
14
 
10
15
  def self.logger
@@ -50,5 +55,6 @@ module Safie
50
55
  self.debugging = false
51
56
  end
52
57
 
58
+ require 'safie/exception'
53
59
  require 'safie/client'
54
60
  require 'safie/access_token'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov
@@ -128,6 +128,7 @@ files:
128
128
  - lib/safie.rb
129
129
  - lib/safie/access_token.rb
130
130
  - lib/safie/client.rb
131
+ - lib/safie/exception.rb
131
132
  - safie.gemspec
132
133
  homepage: https://github.com/nov/safie
133
134
  licenses: