silencer_shop 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: 0fb38ed07576442bf645ab679d4b0faa38f2de8ed7fcee2bb06ec7f948f82058
4
- data.tar.gz: 498e71ac8fb336bafd44c76b3e6efff98029675b210fe5e730398719becdbd1e
3
+ metadata.gz: 38cb8d12db135dd31536cc93d8158b2ba23dc5bc456d5fb6de42ca2a2f38cf81
4
+ data.tar.gz: 0d157839522268b64e4889b160b510ccf21fd17db2fa1fc6366dda1d13af874b
5
5
  SHA512:
6
- metadata.gz: 457c9c8bf80466b5e470bed00b1208bb9f1adb974776ed78c624e44d201c6bb0f9bc219b312c8e019232df2b65fe5639133095b8471f361a19c12516f4c3c1cd
7
- data.tar.gz: 22a8ea41b9da4ba5adb06f85eb4366fb5c18393e50e87a8582c714749a6ea6a4dec49bc45c1fbe033e9285af099401c6f782eaccd0d2a8914002b0623ef10043
6
+ metadata.gz: 4a906308b603fa51def2b7f086d251acd9ed9c025a1b44ca8afa6b150c73bf8a5264e9249dcb84dc3f9cab0dde47bab28d5c5eafc9f8189c04741ff913a5174d
7
+ data.tar.gz: b7abe26ab5262049773bf9e0a935631ce0b82b6626f5b61854c7b5097acaae4eadcf2f5f4aa07cae783e145b92a5c19bd70089c42097b3629aa67d10716dfa3b
data/lib/silencer_shop.rb CHANGED
@@ -26,13 +26,18 @@ module SilencerShop
26
26
  yield(config)
27
27
  end
28
28
 
29
+ def self.sandbox?
30
+ !!config.sandbox
31
+ end
32
+
33
+
29
34
  class Configuration
30
- attr_accessor :proxy_address
31
- attr_accessor :proxy_port
35
+ attr_accessor :proxy_address, :proxy_port, :sandbox
32
36
 
33
37
  def initialize
34
38
  @proxy_address ||= nil
35
39
  @proxy_port ||= nil
40
+ @sandbox ||= true
36
41
  end
37
42
  end
38
43
 
@@ -3,9 +3,11 @@ require 'net/http'
3
3
  module SilencerShop
4
4
  module API
5
5
 
6
- ROOT_API_URL = 'https://silencershopportaldebug.azurewebsites.net/api'.freeze
7
6
  USER_AGENT = "SilencerShopRubyGem/#{SilencerShop::VERSION}".freeze
8
-
7
+ API_URL = {
8
+ development: 'https://silencershopportaldebug.azurewebsites.net/api'.freeze,
9
+ production: 'https://silencershopportal.azurewebsites.net/api'.freeze
10
+ }
9
11
  FILE_UPLOAD_ATTRS = {
10
12
  permitted: %i( file_name file_type file_contents ).freeze,
11
13
  reqired: %i( file_type file_contents ).freeze,
@@ -91,7 +93,7 @@ module SilencerShop
91
93
  end
92
94
 
93
95
  def request_url(endpoint, root_url = nil)
94
- root_url ||= ROOT_API_URL
96
+ root_url ||= (SilencerShop.sandbox? ? API_URL[:development] : API_URL[:production])
95
97
 
96
98
  [root_url, endpoint].join('/')
97
99
  end
@@ -8,6 +8,15 @@ module SilencerShop
8
8
 
9
9
  include SilencerShop::API
10
10
 
11
+ TOKEN_RESOURCE = {
12
+ development: 'https://silencershopstaging.onmicrosoft.com/SilencerShop.Portal'.freeze,
13
+ production: 'https://silencershopsso.onmicrosoft.com/SilencerShop.Portal'.freeze
14
+ }
15
+ TOKEN_URL = {
16
+ development: 'silencershopstaging.onmicrosoft.com/oauth2/token'.freeze,
17
+ production: 'silencershopsso.onmicrosoft.com/oauth2/token'.freeze
18
+ }
19
+
11
20
  attr_accessor :access_token
12
21
 
13
22
  def initialize(options = {})
@@ -32,15 +41,17 @@ module SilencerShop
32
41
  private
33
42
 
34
43
  def authenticate!
44
+ environment = SilencerShop.sandbox? ? :development : :production
45
+ token_resource, token_url = [TOKEN_RESOURCE[environment], TOKEN_URL[environment]]
35
46
  request_data = [
36
- ['resource', CGI.escape('https://silencershopstaging.onmicrosoft.com/SilencerShop.Portal')],
37
47
  ['grant_type', 'client_credentials'],
48
+ ['resource', CGI.escape(token_resource)],
38
49
  ['client_id', CGI.escape(@options[:username])],
39
50
  ['client_secret', CGI.escape(@options[:password])]
40
51
  ].map { |a| a.join('=') }.join('&')
41
52
 
42
53
  response = post_request(
43
- 'silencershopstaging.onmicrosoft.com/oauth2/token',
54
+ token_url,
44
55
  request_data,
45
56
  content_type_header('application/x-www-form-urlencoded'),
46
57
  'https://login.microsoftonline.com'
@@ -21,7 +21,11 @@ module SilencerShop
21
21
  _data.map(&:deep_symbolize_keys)
22
22
  end
23
23
  else
24
- raise SilencerShop::Error::RequestError.new(@response.body)
24
+ if @response.body =~ /unable to verify credentials/i
25
+ SilencerShop::Error::NotAuthorized.new(@response.body)
26
+ else
27
+ raise SilencerShop::Error::RequestError.new(@response.body)
28
+ end
25
29
  end
26
30
  end
27
31
 
@@ -1,3 +1,3 @@
1
1
  module SilencerShop
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silencer_shop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Dill
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-26 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport