my_target_api 1.0.3 → 1.0.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
  SHA1:
3
- metadata.gz: 76fbfb40d5a8fa68ba34cad0129fb48bb8c3286a
4
- data.tar.gz: 3057b9d92c561324c9e671a3aa0f773f0c2da066
3
+ metadata.gz: 29d637416775f256beda271796924a188a577f31
4
+ data.tar.gz: 0764dacd1b9b341b72730ed142866c7c05b02383
5
5
  SHA512:
6
- metadata.gz: b2f698627d980f93785cbe9fa89a8abb7c13b50820f342f4d93a823aa5abcd2412b8c86298608db353518b02cd69e0def79553321ba0c651da499f3c2455a2d5
7
- data.tar.gz: 555210e11984496c154ca494ba299caccc9e4d93beb15009afc6aac4f54d976240e79c4b1b3db4740fe71b6090dd99dae065959857d50d36ab99d0f5b7024eae
6
+ metadata.gz: 89d329c205f1792ce8173ce52af161aee3eaa12b780257ec4cf3714a7f2548ca7ac510477453d2cc6f683ff954480529be9dde9a13a81ab877f58de8c3935f47
7
+ data.tar.gz: cc342e1016adc4a9760b738081cd6b382238b32744e028db90b15156619b6c8a97cd5a2415e3d79c261698d59d69b56be5c4e786e5ce556a97ee6586b56cc79a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my_target_api (1.0.3)
4
+ my_target_api (1.0.4)
5
5
  json (~> 2.0, >= 2.0.0)
6
6
  rest-client (~> 2.0, >= 2.0.0)
7
7
 
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```
10
- gem 'my_target_api', '~> 1.0.3'
10
+ gem 'my_target_api', '~> 1.0.4'
11
11
  ```
12
12
 
13
13
  Or install from command line:
@@ -19,12 +19,14 @@ $ gem install my_target_api
19
19
  ## Usage
20
20
 
21
21
  ### Initialization
22
+
22
23
  ```ruby
23
24
  # You need an access token to use API
24
25
  my_target_api = MyTargetApi.new(access_token)
25
26
  ```
26
27
 
27
28
  ### Resources
29
+
28
30
  ```ruby
29
31
  # root resources
30
32
  campaigns_resource = my_target_api.resource('campaigns')
@@ -36,6 +38,7 @@ remarketing_counters_resource = remarketing_resource.resource('counters')
36
38
  ```
37
39
 
38
40
  ### Create, Read, Update, Delete
41
+
39
42
  ```ruby
40
43
  remarketing_counters_resource.create(counter_id: 121212) # => [{ 'id' => 343434 }]
41
44
 
@@ -48,6 +51,15 @@ campaigns_resource.update(id: 12345, status: 'blocked') # => [{ 'id' => 12345, '
48
51
  remarketing_counters_resource.delete(id: 343434) # => [{ 'success' => true }]
49
52
  ```
50
53
 
54
+ ### File upload
55
+
56
+ ```ruby
57
+ static_resource = my_target_api.resource('content/static', v: 2)
58
+ picture = File.new('path/to/picture.jpg', 'rb')
59
+
60
+ static_resource.create(file: picture, data: { width: 1200, height: 800 })
61
+ ```
62
+
51
63
  ## Exceptions
52
64
 
53
65
  ```ruby
@@ -4,8 +4,8 @@ class MyTargetApi
4
4
  # Error class
5
5
  class ConnectionError < StandardError
6
6
 
7
- def initialize(e)
8
- @exception = e
7
+ def initialize(exception)
8
+ @exception = exception
9
9
  end
10
10
 
11
11
  def message
@@ -4,21 +4,21 @@ class MyTargetApi
4
4
  # Error for request
5
5
  class RequestError < StandardError
6
6
 
7
- def initialize(e)
8
- super build_message e
7
+ def initialize(exception)
8
+ super build_message exception
9
9
  end
10
10
 
11
11
  private
12
12
 
13
- def build_message(e)
14
- body = JSON.parse e.response
13
+ def build_message(exception)
14
+ body = JSON.parse exception.response
15
15
  if body['error']
16
16
  "#{body['error']} : #{body['error_description']}"
17
17
  else
18
18
  body.map { |field, error| "#{field}: #{error}" }.join(', ')
19
19
  end
20
20
  rescue StandardError
21
- e.response
21
+ exception.response
22
22
  end
23
23
 
24
24
  end
@@ -29,6 +29,7 @@ class MyTargetApi
29
29
  def update(params = {})
30
30
  params = prepare_params(params)
31
31
  id = params.delete(:id)
32
+ raise ArgumentError, ':id is required' unless id
32
33
 
33
34
  api.post_request("#{path}/#{id}.json", params)
34
35
  end
@@ -36,6 +37,7 @@ class MyTargetApi
36
37
  def delete(params = {})
37
38
  params = prepare_params(params)
38
39
  id = params.delete(:id)
40
+ raise ArgumentError, ':id is required' unless id
39
41
 
40
42
  api.delete_request("#{path}/#{id}.json", params)
41
43
  end
@@ -49,7 +51,7 @@ class MyTargetApi
49
51
  attr_reader :api, :path
50
52
 
51
53
  def prepare_params(params)
52
- raise UsingError, 'Params must be a Hash' unless params.is_a? Hash
54
+ raise ArgumentError, 'Params must be a Hash' unless params.is_a? Hash
53
55
 
54
56
  params.map do |param, value|
55
57
  [param.to_sym, value]
@@ -2,6 +2,6 @@
2
2
 
3
3
  class MyTargetApi
4
4
 
5
- VERSION = '1.0.3'
5
+ VERSION = '1.0.4'
6
6
 
7
7
  end
data/lib/my_target_api.rb CHANGED
@@ -7,10 +7,10 @@ class MyTargetApi
7
7
 
8
8
  autoload :Resource, 'my_target_api/resource'
9
9
  autoload :Request, 'my_target_api/request'
10
- autoload :Session, 'my_target_api/session'
11
10
 
12
- autoload :ConnectionError, 'my_target_api/errors/connection_error'
13
- autoload :RequestError, 'my_target_api/errors/request_error'
11
+ autoload :ConnectionError, 'my_target_api/connection_error'
12
+ autoload :RequestError, 'my_target_api/request_error'
13
+ autoload :InterfaceError, 'my_target_api/using_error'
14
14
 
15
15
  def initialize(access_token, options = {})
16
16
  @access_token = access_token
data/spec/request_spec.rb CHANGED
@@ -38,5 +38,13 @@ describe MyTargetApi::Request do
38
38
  subject.delete('https://target.my.com/api/v1/remarketing_context_phrases/53.json')
39
39
  ).to eq([{ 'success' => true }])
40
40
  end
41
+
42
+ it 'raises exception on bad statuses' do
43
+ stub_request(:get, 'https://target.my.com/api/v1/wrong_path.json')
44
+ .to_return(body: 'Unknown resource', status: 404)
45
+
46
+ expect { subject.get('https://target.my.com/api/v1/wrong_path.json') }
47
+ .to raise_error(MyTargetApi::RequestError, 'Unknown resource')
48
+ end
41
49
  end
42
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_target_api
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
  - Reshetnikov Ivan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-01 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -154,11 +154,9 @@ files:
154
154
  - README.md
155
155
  - Rakefile
156
156
  - lib/my_target_api.rb
157
- - lib/my_target_api/auth.rb
158
- - lib/my_target_api/errors/connection_error.rb
159
- - lib/my_target_api/errors/request_error.rb
160
- - lib/my_target_api/errors/using_error.rb
157
+ - lib/my_target_api/connection_error.rb
161
158
  - lib/my_target_api/request.rb
159
+ - lib/my_target_api/request_error.rb
162
160
  - lib/my_target_api/resource.rb
163
161
  - lib/my_target_api/version.rb
164
162
  - my_target_api.gemspec
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # see https://target.my.com/doc/api/oauth2
4
-
5
- class MyTargetApi
6
- # authorization
7
- class Auth
8
-
9
- class << self
10
-
11
- include MyTargetApi::Request
12
-
13
- def authorize_url
14
- state = (0...32).map { rand(65..90).chr }.join.downcase
15
- 'https://target.my.com/oauth2/authorize?response_type=code' \
16
- "&client_id=#{MyTargetApi.client_id}&state=#{state}&scope=#{MyTargetApi.scopes}"
17
- end
18
-
19
- # We need new method to receive token using `agency_client_credentials` grant type
20
- # @param client_username [String] client user_name in myTarget
21
- # @return [Hash] containing requested access_token
22
- def get_agency_client_credentials(client_username)
23
- params = { grant_type: 'agency_client_credentials',
24
- agency_client_name: client_username,
25
- v: 2 }
26
- request :post, '/oauth2/token', params
27
- end
28
-
29
- def get_token(code)
30
- params = { grant_type: 'authorization_code', code: code, v: 2 }
31
- request :post, '/oauth2/token', params
32
- end
33
-
34
- def refresh_token(code)
35
- params = { grant_type: 'refresh_token', refresh_token: code, v: 2 }
36
- request :post, '/oauth2/token', params
37
- end
38
-
39
- end
40
-
41
- end
42
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class MyTargetApi
4
- # You are using library in a wrong way
5
- class UsingError < StandardError
6
- end
7
- end