yandex_offers 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 326cda36c6062803f5425fcfe93db6f6d38d9eab
4
+ data.tar.gz: 292b18171bc6b39a90bb25c1e57ea1df0b991a82
5
+ SHA512:
6
+ metadata.gz: 3346a6caac2a4f2885941fa8beb33f2fd521ca55a59d17b41e808034eabb93509fbf6eafdb1f5f1527e4d3cfc1fbcc5127ca6176311828b33a827d9284fecb79
7
+ data.tar.gz: bfc4aecfd754b274a4cc3c2e038d72b0cbb1d6baf7140a5d055fa60af4d5b8e394ab7af6e7cd4135761449847982096f5dd2f928f8a9dfdb4e178fef4c03e02f
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in yandex_offers.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # YandexOffers
2
+
3
+ A Ruby client for YandexOffers API
4
+
5
+ API Doc: https://tech.yandex.ru/money/doc/offers/about-docpage
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yandex_offers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yandex_offers
22
+
23
+ ## Usage
24
+
25
+ 1. Set configuration
26
+ ```ruby
27
+ YandexOffers.configure do |config|
28
+ config.login = "login"
29
+ config.password = "password"
30
+ config.base_url = "base_url"
31
+ end
32
+ ```
33
+
34
+ 2. Use Client
35
+ ```ruby
36
+ client = YandexOffers::Client.new
37
+ client.campaigns.create
38
+ ```
39
+
40
+ It performs `campaigns/create` request to API
41
+
42
+ ## TODO
43
+
44
+ 1. Add argument validation in api methods
45
+ 2. Add error handling
46
+ 2. Improve test coverage
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fenec/yandex_offers.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yandex_offers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require "yandex_offers/version"
2
+ require "yandex_offers/authorization"
3
+ require "yandex_offers/configuration"
4
+ require "yandex_offers/client"
5
+ require "yandex_offers/request"
6
+ require "yandex_offers/api/v1/campaigns"
7
+
8
+ module YandexOffers
9
+ class << self
10
+ def configure
11
+ yield configuration
12
+ end
13
+
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,48 @@
1
+ module YandexOffers
2
+ module Api
3
+ module V1
4
+ class Campaigns
5
+
6
+ def create(*args)
7
+ options = { body: args, headers: headers }
8
+ Request.post("/campaigns/create", options)
9
+ end
10
+
11
+ def start(*args)
12
+ options = { body: args, headers: headers }
13
+ Request.post("/campaigns/start", options)
14
+ end
15
+
16
+ def stop(*args)
17
+ options = { body: args, headers: headers }
18
+ Request.post("/campaigns/stop", options)
19
+ end
20
+
21
+ def get(*args)
22
+ options = { body: args, headers: headers }
23
+ Request.post("/campaigns/get", options)
24
+ end
25
+
26
+ def get_all_campaigns(*args)
27
+ options = { body: args, headers: headers }
28
+ Request.post("/campaigns/get_all_campaigns", options)
29
+ end
30
+
31
+ 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}"} }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ module YandexOffers
2
+ class Authorization
3
+ def get_token
4
+ options = { body: { login: YandexOffers.configuration.login, password: YandexOffers.configuration.password } }
5
+ response = Request.post("/users/login", options)
6
+ response["accessToken"]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module YandexOffers
2
+ class Client
3
+ def method_missing(name, *args, &block)
4
+ klass_name = name.to_s.capitalize
5
+ YandexOffers::Api::V1.const_get("#{klass_name}").new
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module YandexOffers
2
+ class Configuration
3
+ attr_accessor :login, :password, :base_url
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'httparty'
2
+
3
+ class YandexOffers::Request
4
+ include HTTParty
5
+
6
+ def self.post(url, options)
7
+ response = HTTParty.post("#{YandexOffers.configuration.base_url}#{url}", options)
8
+ JSON.parse(response)
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module YandexOffers
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "yandex_offers/version"
5
+ require "pry"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "yandex_offers"
9
+ spec.version = YandexOffers::VERSION
10
+ spec.authors = ["fenec"]
11
+ spec.email = ""
12
+
13
+ spec.summary = "Client for Yandex Offers API"
14
+ spec.description = "Client for Yandex Offers API"
15
+ spec.homepage = ""
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rspec-mocks", "~> 3.0"
28
+ spec.add_development_dependency "webmock"
29
+ spec.add_development_dependency "pry"
30
+
31
+ spec.add_dependency "httparty", "~> 0.13"
32
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yandex_offers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fenec
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-mocks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.13'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.13'
111
+ description: Client for Yandex Offers API
112
+ email: ''
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ".gitignore"
118
+ - ".rspec"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - bin/console
124
+ - bin/setup
125
+ - lib/yandex_offers.rb
126
+ - lib/yandex_offers/api/v1/campaigns.rb
127
+ - lib/yandex_offers/authorization.rb
128
+ - lib/yandex_offers/client.rb
129
+ - lib/yandex_offers/configuration.rb
130
+ - lib/yandex_offers/request.rb
131
+ - lib/yandex_offers/version.rb
132
+ - yandex_offers.gemspec
133
+ homepage: ''
134
+ licenses: []
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.12
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Client for Yandex Offers API
156
+ test_files: []