bwapi 1.0.3 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4692c7ee38a0d1359f41ff3e69ed9e5aa80c6d4
4
- data.tar.gz: bb7baf572ec356c81a815b4f4e1452d17d01e17b
3
+ metadata.gz: 7c2e256ae41a00031f7d4c5f62d2cab076b34e80
4
+ data.tar.gz: d07297df0f274cbe15e42f07492382a3d5b691e7
5
5
  SHA512:
6
- metadata.gz: e1339f1f0921fece977f5b524dc70873d0e6a1388259c0cbe9db686a79f5226a3619e0a7125b91e51cd874a2e841d7160c0ea11b310214c4f56483771f7826ba
7
- data.tar.gz: 8cdfb5a20bbc1df62aa829fb7db51f69be3d7aed5ae758845732738198a8aa1c74e83d16ed0e1106f459c50930b28ebdd1bb009efa726dbcdb3234d3ff661c76
6
+ metadata.gz: 7e6ed60c84b9354250f1e9dead2923020f7b64690d1eada936b9d7acfd590dd006d9e51ad6158abc8f9eee3d9311c3b9b39d3d5c9892b9c676a55ad3b54a8930
7
+ data.tar.gz: 752d23785c294481eae8e43eeab66ad6089f74dd7bfbca75a6b97ab858c7128237ea0e9c056f1a58c17ef9015601ab979fd4f090c84bb6fe7bf0d6523ce9f1e2
@@ -9,12 +9,12 @@ module BWAPI
9
9
  begin
10
10
  get "logout"
11
11
  ensure
12
+ self.access_token = nil
13
+ self.refresh_token = nil
12
14
  self.username = nil
13
15
  self.password = nil
14
- self.access_token = nil
15
16
  self.client_id = nil
16
- self.access_token = nil
17
- self.refresh_token = nil
17
+ self.grant_type = nil
18
18
  self.expires_in = nil
19
19
  end
20
20
  end
@@ -21,20 +21,7 @@ module BWAPI
21
21
  force_urlencoded: true
22
22
  }.merge opts
23
23
 
24
- begin
25
- creds = post 'oauth/token', opts
26
- rescue BWAPI::BWError
27
- return false
28
- else
29
- self.access_token = creds.access_token
30
- self.expires_in = creds.expires_in
31
-
32
- if application_client?
33
- self.refresh_token = creds.refresh_token
34
- end
35
-
36
- return true
37
- end
24
+ oauth_request opts
38
25
  end
39
26
  alias :login :oauth_token
40
27
 
@@ -46,7 +33,7 @@ module BWAPI
46
33
  # @option opts [String] grant_type Grant type of user
47
34
  # @option opts [String] client_id Client id
48
35
  # @option opts [String] force_urlencoded Force urlencoded
49
- def oauth_refresh_token opts={}
36
+ def oauth_refresh_token opts={}, refresh_token = nil
50
37
  opts = {
51
38
  username: username,
52
39
  password: password,
@@ -56,22 +43,29 @@ module BWAPI
56
43
  force_urlencoded: true
57
44
  }.merge opts
58
45
 
46
+ oauth_request opts
47
+ end
48
+ alias :refresh :oauth_refresh_token
49
+
50
+ # Sends a oauth request
51
+ #
52
+ # @param opts [Hash] options hash of parameters
53
+ def oauth_request opts
59
54
  begin
60
55
  creds = post 'oauth/token', opts
61
56
  rescue BWAPI::BWError
62
- return false
57
+ false
63
58
  else
64
59
  self.access_token = creds.access_token
65
60
  self.expires_in = creds.expires_in
66
61
 
67
62
  if application_client?
68
- self.access_token = creds.access_token
63
+ self.refresh_token = creds.refresh_token
69
64
  end
70
65
 
71
- return true
66
+ true
72
67
  end
73
68
  end
74
- alias :refresh :oauth_refresh_token
75
69
 
76
70
  end
77
71
  end
@@ -18,7 +18,7 @@ module BWAPI
18
18
  # Get all projects
19
19
  #
20
20
  # @param opts [Hash] options hash of parameters
21
- # @option opts [Integer] page Page of projects to retrieve
21
+ # @option opts [Integer] pagePage of projects to retrieve
22
22
  # @option opts [Integer] pageSize Results per page of results
23
23
  # @return [Hashie::Mash] All projects
24
24
  def projects opts={}
data/lib/bwapi/request.rb CHANGED
@@ -50,35 +50,38 @@ module BWAPI
50
50
 
51
51
  private
52
52
 
53
- # Perform a request
53
+ # Sets connection options
54
54
  #
55
- # @param method [String] Type of request path
56
- # @param path [String] URL path to send request
57
- # @param opts [Hash] Request parameters
58
- # @return [Hashie::Mash] Response
59
- def request method, path, opts={}
60
- conn_opts = {
55
+ # @param opts [Hash] hash of opts passed
56
+ # @return [Hash] connection options
57
+ def connection_options opts
58
+ {
61
59
  :headers => {
60
+ :authorization => access_token ? "bearer #{access_token}" : "",
62
61
  :user_agent => user_agent
63
62
  },
64
63
  :force_urlencoded => opts.delete(:force_urlencoded) || false,
65
64
  :url => api_endpoint,
66
65
  :ssl => {:verify => verify_ssl}
67
66
  }
67
+ end
68
68
 
69
- response = connection(conn_opts).send(method) do |request|
70
- # Add token to the header
71
- if access_token
72
- request.headers[:authorization] = "bearer #{access_token}"
73
- end
74
-
69
+ # Perform a request
70
+ #
71
+ # @param method [String] Type of request path
72
+ # @param path [String] URL path to send request
73
+ # @param opts [Hash] Request parameters
74
+ # @return [Hashie::Mash] Response
75
+ def request method, path, opts={}
76
+ conn_options = connection_options opts
77
+ response = connection(conn_options).send(method) do |request|
75
78
  case method
76
79
  when :get
77
80
  request.url path, opts
78
81
  when :delete
79
82
  request.url path, opts
80
83
  when :patch, :post, :put
81
- if conn_opts[:force_urlencoded]
84
+ if conn_options[:force_urlencoded]
82
85
  request.url path, opts
83
86
  else
84
87
  request.path = path
data/lib/bwapi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BWAPI
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bwapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Chrisp
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  requirements: []
196
196
  rubyforge_project:
197
- rubygems_version: 2.0.5
197
+ rubygems_version: 2.0.7
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Brandwatch v2 API Wrapper