sinatra_touchsell_store_app 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60bd876ce986ae78a62b671b3efbd03719c2fe3a
4
+ data.tar.gz: bbd2ba370c6dc4072038cdd39462c847b3612f89
5
+ SHA512:
6
+ metadata.gz: f19d2f27276b482d43d94687630bba43f014412674e17988074a52bb45fcec11f81509df14e2a2032333b841d411b10cce938f85be2c7903aad87ef0582af1ce
7
+ data.tar.gz: 0496afed6a9d5f9469151b84d88699621859e31bbaa5a2c63a45e7012fe1618f226f8c4396662ef48394ccbbe8cc45299127ce757fd8045fef1a081ea41ee087
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/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sinatra_touchsell_store_app.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Gauthier Monserand
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,37 @@
1
+ # SinatraTouchsellStoreApp
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'sinatra_touchsell_store_app'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sinatra_touchsell_store_app
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/touchsell/sinatra_touchsell_store_app.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
37
+
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 "sinatra_touchsell_store_app"
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,84 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/flash'
3
+ require 'oauth2'
4
+ require 'haml'
5
+
6
+ load 'env.rb' if File.exists?('env.rb')
7
+
8
+ module Sinatra
9
+ module OAuth2Store
10
+ DEFAULT_API_HOST='https://bo.touch-sell.net/'
11
+
12
+ DEFAULT_OAUTH2_PROVIDER='https://bo.touch-sell.net/'
13
+
14
+ module Helpers
15
+
16
+ def clients
17
+ @clients ||= api.get_clients
18
+ end
19
+
20
+ def signed_in?
21
+ current_user != nil
22
+ end
23
+
24
+ def current_user
25
+ @current_user ||= api.current_user
26
+ rescue
27
+ session[:access_token] = nil
28
+ end
29
+
30
+ def api
31
+ site = ENV['SITE'] || OAuth2Store::DEFAULT_API_HOST
32
+ @api ||= TSAPI.new("#{site}/api/v1/", session[:access_token])
33
+ end
34
+
35
+ def oauth2_client(token_method = :post)
36
+ OAuth2::Client.new(
37
+ ENV['OAUTH2_CLIENT_ID'],
38
+ ENV['OAUTH2_CLIENT_SECRET'],
39
+ site: ENV['SITE'] || OAuth2Store::DEFAULT_OAUTH2_PROVIDER,
40
+ token_method: token_method
41
+ )
42
+ end
43
+
44
+ def access_token
45
+ OAuth2::AccessToken.new(oauth2_client, session[:access_token], refresh_token: session[:refresh_token])
46
+ end
47
+
48
+ def redirect_uri
49
+ ENV['OAUTH2_CLIENT_REDIRECT_URI']
50
+ end
51
+
52
+ end
53
+
54
+ def self.registered(app)
55
+ app.helpers OAuth2Store::Helpers
56
+ app.enable :sessions
57
+ app.register Sinatra::Flash
58
+
59
+ app.get '/sign_in' do
60
+ scope = params[:scope] || 'public read'
61
+ redirect oauth2_client.auth_code.authorize_url(redirect_uri: redirect_uri, scope: scope)
62
+ end
63
+
64
+ app.get '/sign_out' do
65
+ session[:access_token] = nil
66
+ redirect '/'
67
+ end
68
+
69
+ app.get '/callback' do
70
+ begin
71
+ new_token = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
72
+ session[:access_token] = new_token.token
73
+ session[:refresh_token] = new_token.refresh_token
74
+ redirect '/'
75
+ rescue OAuth2::Error
76
+ flash[:error] = params[:error]
77
+ flash[:error_description] = params[:error_description]
78
+ redirect '/'
79
+ end
80
+ end
81
+ end
82
+ end
83
+ #register OAuth2Store
84
+ end
@@ -0,0 +1,6 @@
1
+ require "sinatra_touchsell_store_app/version"
2
+ require "sinatra_touchsell_store_app/api"
3
+ require "sinatra/oauth2store"
4
+
5
+ module SinatraTouchsellStoreApp
6
+ end
@@ -0,0 +1,66 @@
1
+ require "stringio"
2
+ require "pathname"
3
+ require 'ostruct'
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+ class TSAPI
8
+ def initialize(base_url, token)
9
+ @base_url = base_url
10
+ @token = token
11
+ end
12
+
13
+ def get url, params={}
14
+ params[:access_token] = @token
15
+ #puts "get: #{@base_url}#{url} with params #{params}"
16
+ RestClient.get "#{@base_url}#{url}", {
17
+ params: params,
18
+ }
19
+ end
20
+
21
+ def put url, params = {}
22
+ params[:access_token] = @token
23
+ RestClient.put "#{@base_url}#{url}", params, {
24
+ }
25
+ end
26
+
27
+ def post url, params = {}
28
+ params[:access_token] = @token
29
+ RestClient.post "#{@base_url}#{url}", params, {
30
+ "Content-Type": "application/json",
31
+ Accept: :json
32
+ }
33
+ end
34
+
35
+ def parse(response)
36
+ JSON.parse(response, object_class: OpenStruct)
37
+ end
38
+
39
+ def current_user
40
+ parse( get("me") )
41
+ end
42
+
43
+ def get_clients(params={})
44
+ parse( get("/clients", params) )
45
+ end
46
+
47
+ def get_kpi(params={})
48
+ parse( get("/stats/kpi", params) )
49
+ end
50
+
51
+ def get_nodes(params={})
52
+ parse( get("/nodes", params) )
53
+ end
54
+
55
+ def get_medias(params={})
56
+ parse( get("/medias", params) )
57
+ end
58
+
59
+ def get_form_submits(id)
60
+ parse( get("/forms/#{id}/submits"))
61
+ end
62
+
63
+ def get_clients(params={})
64
+ parse( get("/clients", params))
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module SinatraTouchsellStoreApp
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra_touchsell_store_app/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sinatra_touchsell_store_app"
8
+ spec.version = SinatraTouchsellStoreApp::VERSION
9
+ spec.authors = ["Gauthier Monserand"]
10
+ spec.email = ["dev@touch-sell.com"]
11
+
12
+ spec.summary = %q{Quickly generate Touch & Sell store app}
13
+ spec.description = %q{Helpers for Sinatra to generate Touch & Sell store application}
14
+ spec.homepage = "http://rubygems.org/gems/sinatra_touchsell_store_app"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ #end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+
37
+ spec.add_runtime_dependency 'sinatra', '~> 2.0'
38
+ spec.add_runtime_dependency 'sinatra-flash', '~> 0.3.0'
39
+ spec.add_runtime_dependency 'thin'
40
+ spec.add_runtime_dependency 'haml'
41
+ spec.add_runtime_dependency 'tilt'
42
+ spec.add_runtime_dependency 'rest-client'
43
+ spec.add_runtime_dependency 'oauth2', '~> 1.3.1'
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra_touchsell_store_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gauthier Monserand
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-flash
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: thin
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
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: haml
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tilt
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rest-client
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: oauth2
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.3.1
153
+ description: Helpers for Sinatra to generate Touch & Sell store application
154
+ email:
155
+ - dev@touch-sell.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - lib/sinatra/oauth2store.rb
170
+ - lib/sinatra_touchsell_store_app.rb
171
+ - lib/sinatra_touchsell_store_app/api.rb
172
+ - lib/sinatra_touchsell_store_app/version.rb
173
+ - sinatra_touchsell_store_app.gemspec
174
+ homepage: http://rubygems.org/gems/sinatra_touchsell_store_app
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.8
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Quickly generate Touch & Sell store app
198
+ test_files: []