safie 0.0.1

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
+ SHA256:
3
+ metadata.gz: d51306af691333c0dbabc183f743423b5b57e95dd25780ebbb4eaa815836b08e
4
+ data.tar.gz: 19253ab2bab74b84b9db97cedb6e29b0ee726e7c64ffb606f970fd2af5747785
5
+ SHA512:
6
+ metadata.gz: 79775c99ad4ede0af6486aaa16bc8238dbe33cfa1c90b1406b1f4557382c7c0121141b05aff6f14b630df0943b018a0ba77aebbdb11d8e2a6d2e446ef4996c8f
7
+ data.tar.gz: 6e6c332f7f83157ce369f75070d530cf3ad839c3afbee6ef8c218cfe57f1aac9919238fbb58afd6bd66c14c403342ef4a4fe3f4b4d6651c2ce3f12a4b867a709
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in safie.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 nov
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Safie
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/safie`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'safie'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install safie
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/safie.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "safie"
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,13 @@
1
+ module Safie
2
+ class AccessToken < Rack::OAuth2::AccessToken::Bearer
3
+ undef_required_attributes :client
4
+
5
+ def initialize(access_token, attributes = {})
6
+ super attributes.merge(access_token: access_token)
7
+ end
8
+
9
+ def token_info!
10
+ get File.join(ISSUER, '/auth/tokeninfo')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ module Safie
2
+ class Client < Rack::OAuth2::Client
3
+ class Error < Rack::OAuth2::Client::Error; end
4
+
5
+ def initialize(attributes)
6
+ attributes_with_default = {
7
+ authorization_endpoint: File.join(ISSUER, '/auth/authorize'),
8
+ token_endpoint: File.join(ISSUER, '/auth/token')
9
+ }.merge(attributes)
10
+ super attributes_with_default
11
+ end
12
+
13
+ def authorization_uri(params = {})
14
+ params[:scope] ||= DEFAULT_SCOPE
15
+ super
16
+ end
17
+
18
+ def access_token!(options = {})
19
+ options[:scope] ||= DEFAULT_SCOPE
20
+ super :body, options
21
+ end
22
+
23
+ private
24
+
25
+ def handle_success_response(response)
26
+ token_hash = JSON.parse(response.body).with_indifferent_access
27
+ AccessToken.new token_hash.delete(:access_token), token_hash
28
+ end
29
+
30
+ def handle_error_response(response)
31
+ error = JSON.parse(response.body).with_indifferent_access
32
+ raise Error.new(response.status, error)
33
+ end
34
+ end
35
+ end
data/lib/safie.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'rack/oauth2'
2
+
3
+ module Safie
4
+ ISSUER = 'https://app.safie.link'
5
+ DEFAULT_SCOPE = :use
6
+ VERSION = ::File.read(
7
+ ::File.join(::File.dirname(__FILE__), '../VERSION')
8
+ ).chomp
9
+
10
+ def self.logger
11
+ @@logger
12
+ end
13
+ def self.logger=(logger)
14
+ @@logger = logger
15
+ end
16
+ self.logger = Logger.new(STDOUT)
17
+ self.logger.progname = 'Safie'
18
+
19
+ @sub_protocols = [
20
+ Rack::OAuth2
21
+ ]
22
+ def self.debugging?
23
+ @@debugging
24
+ end
25
+ def self.debugging=(boolean)
26
+ @sub_protocols.each do |klass|
27
+ klass.debugging = boolean
28
+ end
29
+ @@debugging = boolean
30
+ end
31
+ def self.debug!
32
+ @sub_protocols.each do |klass|
33
+ klass.debug!
34
+ end
35
+ self.debugging = true
36
+ end
37
+ def self.debug(&block)
38
+ sub_protocol_originals = @sub_protocols.inject({}) do |sub_protocol_originals, klass|
39
+ sub_protocol_originals.merge!(klass => klass.debugging?)
40
+ end
41
+ original = self.debugging?
42
+ debug!
43
+ yield
44
+ ensure
45
+ @sub_protocols.each do |klass|
46
+ klass.debugging = sub_protocol_originals[klass]
47
+ end
48
+ self.debugging = original
49
+ end
50
+ self.debugging = false
51
+ end
52
+
53
+ require 'safie/client'
54
+ require 'safie/access_token'
data/safie.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'safie'
3
+ spec.version = File.read('VERSION')
4
+ spec.authors = ['nov']
5
+ spec.email = ['nov@matake.jp']
6
+
7
+ spec.summary = %q{Safie API Client}
8
+ spec.description = %q{Safie API Client in Ruby.}
9
+ spec.homepage = 'https://github.com/nov/safie'
10
+ spec.license = 'MIT'
11
+
12
+ # Specify which files should be added to the gem when it is released.
13
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
14
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'rack-oauth2', '~> 1.10'
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rspec-its'
26
+ spec.add_development_dependency 'webmock'
27
+ spec.add_development_dependency 'simplecov'
28
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - nov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Safie API Client in Ruby.
112
+ email:
113
+ - nov@matake.jp
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - VERSION
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/safie.rb
129
+ - lib/safie/access_token.rb
130
+ - lib/safie/client.rb
131
+ - safie.gemspec
132
+ homepage: https://github.com/nov/safie
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.0.3
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Safie API Client
155
+ test_files: []