silencer_shop 1.0.0 → 1.1.4

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: 37df1cda1a90d164d017a1f186baeb2105628159c98c478ad4135c5b05b26e14
4
+ data.tar.gz: 9291d75904fddd9313e4a67bb5f45f0988c09c5d0ee094f692ec74e65182eaaf
5
5
  SHA512:
6
- metadata.gz: 457c9c8bf80466b5e470bed00b1208bb9f1adb974776ed78c624e44d201c6bb0f9bc219b312c8e019232df2b65fe5639133095b8471f361a19c12516f4c3c1cd
7
- data.tar.gz: 22a8ea41b9da4ba5adb06f85eb4366fb5c18393e50e87a8582c714749a6ea6a4dec49bc45c1fbe033e9285af099401c6f782eaccd0d2a8914002b0623ef10043
6
+ metadata.gz: ec85b9fb8ed25ddd55bec12260f51647500bed27702d85a2359049889297b73f33ba40c9bd5a8292ff23753c47e014c86b470272f9c2e6ae1b930a81cbf1a9d7
7
+ data.tar.gz: f588c3004bad236b3596d52f42eb9e05fb9479b4b4fe43429f33da0b44e85aebaee83c8db0754216d0de7145f17431b64bde76f30a151af2f249e5f79348082f
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'
@@ -1,6 +1,8 @@
1
1
  module SilencerShop
2
2
  class Response
3
3
 
4
+ attr_accessor :success
5
+
4
6
  def initialize(response)
5
7
  @response = response
6
8
 
@@ -13,15 +15,24 @@ module SilencerShop
13
15
  SilencerShop::Error::NoContent.new(@response.body)
14
16
  when Net::HTTPOK, Net::HTTPSuccess
15
17
  _data = (JSON.parse(@response.body) if @response.body.present?)
16
-
17
18
  @data = case
18
19
  when _data.is_a?(Hash)
19
20
  _data.deep_symbolize_keys
20
21
  when _data.is_a?(Array)
21
22
  _data.map(&:deep_symbolize_keys)
22
23
  end
24
+
25
+ if @data.is_a?(Hash) && @data.has_key?(:ErrorMessage)
26
+ raise SilencerShop::Error::RequestError.new(@response.body)
27
+ end
28
+
29
+ self.success = true
23
30
  else
24
- raise SilencerShop::Error::RequestError.new(@response.body)
31
+ if @response.body =~ /unable to verify credentials/i
32
+ SilencerShop::Error::NotAuthorized.new(@response.body)
33
+ else
34
+ raise SilencerShop::Error::RequestError.new(@response.body)
35
+ end
25
36
  end
26
37
  end
27
38
 
@@ -38,7 +49,7 @@ module SilencerShop
38
49
  end
39
50
 
40
51
  def success?
41
- !!self[:success] && self[:errors].empty?
52
+ !!success
42
53
  end
43
54
 
44
55
  end
@@ -1,3 +1,3 @@
1
1
  module SilencerShop
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.4'.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.4
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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport