smileback 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b05d7351a144ae46723b829b59dc9ec1d8f34e8aecedadefdfd05b9af5174ad7
4
+ data.tar.gz: 51bc40e7062542827a4215e499b812c97a17ede35aa5cb94c0cd6be17265e805
5
+ SHA512:
6
+ metadata.gz: 24ed8691fffda99b3739df1f3eb5020cee646874e6c701bc29add00208d5c7b875f29c64d11290dd47074f550a93564d0119a35e92dd057174608de05d35b661
7
+ data.tar.gz: 48481e6060e920d4bcfb30344954082fa46bcb0ae488ebe4e7521c668d507e06677d0bc709e9af41cc76a1bedf4bffaaa63f888af7e3e352981d43ad7e065fd9
@@ -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
+ *.gem
11
+ /.idea
12
+ .ruby-*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in smileback.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Kevin Pheasey
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.
@@ -0,0 +1,34 @@
1
+ # Smileback
2
+
3
+ This gem combines an OAuth2 strategy and general API access for SmileBack.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'smileback'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+
18
+ ## Usage
19
+
20
+ TODO: Write usage instructions here
21
+
22
+ ## Development
23
+
24
+ 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.
25
+
26
+ 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).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/smileback.
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smileback"
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__)
@@ -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,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Smileback < OmniAuth::Strategies::OAuth2
8
+ option :name, 'smileback'
9
+
10
+ option :client_options, {
11
+ site: ENV['SMILEBACK_SITE'],
12
+ authorize_url: ENV['SMILEBACK_AUTHORIZATION_URL'],
13
+ token_url: ENV['SMILEBACK_TOKEN_URL']
14
+ }
15
+
16
+ def callback_url
17
+ full_host + script_name + callback_path
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ require 'oauth2'
2
+ require 'httparty'
3
+ require 'smileback/version'
4
+ require 'smileback/configuration'
5
+ require 'omniauth/strategies/smileback'
6
+
7
+ module Smileback
8
+ class Client
9
+ include HTTParty
10
+
11
+ debug_output $stdout
12
+
13
+ def initialize(token:, refresh_token:, expires_at:, expires: true)
14
+ self.class.base_uri Smileback.configuration.api_base_url
15
+
16
+ @access_token = OAuth2::AccessToken.new(
17
+ oauth2_client,
18
+ token, { expires_at: expires_at, refresh_token: refresh_token }
19
+ )
20
+ end
21
+
22
+ # Latest OAuth2 credentials based on access_token. The original token may need to be refreshed during usage,
23
+ # so always check here for the latest values when finished.
24
+ #
25
+ # @return [Hash]
26
+ def credentials
27
+ {
28
+ token: @access_token.token,
29
+ refresh_token: @access_token.refresh_token,
30
+ expires_at: @access_token.expires_at,
31
+ expires: true
32
+ }
33
+ end
34
+
35
+ # Make a GET request to the API.
36
+ #
37
+ # @param path [String] endpoint; '/v3/reviews/'
38
+ # @param query [Hash] query params; { modified_since: '2017-10-27T07:43:15Z' }
39
+ # @return [HTTParty::Response]
40
+ def get(path, query = {})
41
+ @access_token.refresh! if @access_token.expired?
42
+
43
+ self.class.get(path, {
44
+ headers: { Authorization: "Bearer #{@access_token.token}" },
45
+ query: query
46
+ })
47
+ end
48
+
49
+ private
50
+
51
+ def oauth2_client
52
+ @oauth2_client ||= OAuth2::Client.new(
53
+ Smileback.configuration.client_id,
54
+ Smileback.configuration.client_secret, {
55
+ token_url: "#{Smileback.configuration.api_base_url}/token/"
56
+ }
57
+ )
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,17 @@
1
+ module Smileback
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield(configuration)
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :api_base_url, :client_id, :client_secret
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Smileback
2
+ VERSION = "0.2.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smileback/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'smileback'
8
+ spec.version = Smileback::VERSION
9
+ spec.authors = ['Kevin Pheasey']
10
+ spec.email = ['kevin@kpsoftware.io']
11
+
12
+ spec.summary = %q{An API v3 wrapper for smileback with OmniAuth OAuth2 strategy}
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/kpsoftware/smileback'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'omniauth', '~> 1.2'
23
+ spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
24
+ spec.add_runtime_dependency 'oauth2', '~> 1.4'
25
+ spec.add_runtime_dependency 'httparty', '~> 0.13'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.16'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smileback
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Pheasey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.13'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.16'
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
+ description: An API v3 wrapper for smileback with OmniAuth OAuth2 strategy
112
+ email:
113
+ - kevin@kpsoftware.io
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
+ - bin/console
126
+ - bin/setup
127
+ - lib/omniauth/strategies/smileback.rb
128
+ - lib/smileback.rb
129
+ - lib/smileback/configuration.rb
130
+ - lib/smileback/version.rb
131
+ - smileback.gemspec
132
+ homepage: https://github.com/kpsoftware/smileback
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
+ rubyforge_project:
152
+ rubygems_version: 2.7.6
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: An API v3 wrapper for smileback with OmniAuth OAuth2 strategy
156
+ test_files: []