yandex_offers 0.1.1 → 0.1.2

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: f46b4d86898e9e4b4a641880b887841fa4cccf96
4
- data.tar.gz: 1aef5e6647500a98be37d6ff7c5645dbcf6fb6c3
3
+ metadata.gz: 489c45ab21294d78a111893deabbb1a7c58309e0
4
+ data.tar.gz: 613bd92aca987595be301a70bb712b272ae404a9
5
5
  SHA512:
6
- metadata.gz: 7f893196584b310028cbb452f548fa14efacfd442b859702b177b0b113be8d8309e505f05580f8c7caffdb9c451a16411c22ea8bb24cadb43633e05238b0e4eb
7
- data.tar.gz: 7ffe28e127516709cd5f8707ed10ce0659a1d4f4a46c97229d2d0cdddc3a1f346a9d940b4856adc3774c8e58e1684830a7fa312862947202ef733f253398c128
6
+ metadata.gz: 1140b4588c2f9c59b94460c996ea07f95b681344b6da11043b55753f60541f95e338b38e7b2d37056c56d353e8fcec49c1a6cca211803364f76832a9aa03b479
7
+ data.tar.gz: 19e6664e933f84a1336be6b6fbc7ac334fe396c6f1976b85c95cd02009f23be09d7c0f72edc1d594c72bbf0cf916c6f5c4d0ade58d391b722ae3fa07dc8588e0
@@ -4,43 +4,27 @@ module YandexOffers
4
4
  class Campaigns
5
5
 
6
6
  def create(*args)
7
- options = { body: args, headers: headers }
8
- Request.post("/campaigns/create", options)
7
+ Request.post_with_authorization("/campaigns/create", args)
9
8
  end
10
9
 
11
10
  def start(*args)
12
- options = { body: args, headers: headers }
13
- Request.post("/campaigns/start", options)
11
+ Request.post_with_authorization("/campaigns/start", args)
14
12
  end
15
13
 
16
14
  def stop(*args)
17
- options = { body: args, headers: headers }
18
- Request.post("/campaigns/stop", options)
15
+ Request.post_with_authorization("/campaigns/stop", args)
19
16
  end
20
17
 
21
18
  def get(*args)
22
- options = { body: args, headers: headers }
23
- Request.post("/campaigns/get", options)
19
+ Request.post_with_authorization("/campaigns/get", args)
24
20
  end
25
21
 
26
22
  def get_all_campaigns(*args)
27
- options = { body: args, headers: headers }
28
- Request.post("/campaigns/get_all_campaigns", options)
23
+ Request.post_with_authorization("/campaigns/get-all-campaigns", args)
29
24
  end
30
25
 
31
26
  def add_pins(*args)
32
- options = { body: args, headers: headers }
33
- Request.post("/campaigns/add_pins", options)
34
- end
35
-
36
- private
37
-
38
- def token
39
- @token ||= Authorization.new.get_token
40
- end
41
-
42
- def headers
43
- { headers: { Authorization: "Bearer #{token}"} }
27
+ Request.post_with_authorization("/campaigns/add-pins", args)
44
28
  end
45
29
  end
46
30
  end
@@ -1,8 +1,8 @@
1
1
  module YandexOffers
2
2
  class Authorization
3
3
  def get_token
4
- options = { body: { login: YandexOffers.configuration.login, password: YandexOffers.configuration.password } }
5
- response = Request.post("/users/login", options)
4
+ body = { login: YandexOffers.configuration.login, password: YandexOffers.configuration.password }
5
+ response = Request.post("/users/login", body)
6
6
  response["accessToken"]
7
7
  end
8
8
  end
@@ -3,8 +3,29 @@ require 'httparty'
3
3
  class YandexOffers::Request
4
4
  include HTTParty
5
5
 
6
- def self.post(url, options)
7
- options[:format] = :json
8
- HTTParty.post("#{YandexOffers.configuration.base_url}#{url}", options).parsed_response
6
+ class << self
7
+ def post(url, body)
8
+ options = {}
9
+ options[:format] = :json
10
+ options[:body] = body
11
+ options[:headers] = self.headers
12
+ HTTParty.post("#{YandexOffers.configuration.base_url}#{url}", options).parsed_response
13
+ end
14
+
15
+ def post_with_authorization(url, body)
16
+ options = {}
17
+ options[:format] = :json
18
+ options[:body] = body.to_json
19
+ options[:headers] = self.headers.merge({"Authorization" => "Bearer #{self.token}"})
20
+ HTTParty.post("#{YandexOffers.configuration.base_url}#{url}", options).parsed_response
21
+ end
22
+
23
+ def token
24
+ @token ||= YandexOffers::Authorization.new.get_token
25
+ end
26
+
27
+ def headers
28
+ @headers ||= { "Content-Type" => "application/json", "Accept" => "application/json" }
29
+ end
9
30
  end
10
31
  end
@@ -1,3 +1,3 @@
1
1
  module YandexOffers
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex_offers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fenec
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler