targetmy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66490781d279ddc675a08efc2a78fa67e8a241d7
4
+ data.tar.gz: b55758cc8f3e16e19840b0806ddecfebe7264736
5
+ SHA512:
6
+ metadata.gz: e1d239df0a79c845030c167949a3996c13ca9a87dfc4fb6edd3ab72b821d2caea4cada2e27d1fc48e17d17cf6069de1b12113ea1a03074ec46179602db4a6765
7
+ data.tar.gz: fd5077936291ff971eafb969e50c6397a091af3bb649a1064ca3e3dae88eaabed8e010f26e07ac34ea79f82ddccb35a460fcfb0c95ff373a3604ad88d1ada451
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
+ /.idea
12
+ spec/credentials.yml
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.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in targetmy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 dimag
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Targetmy
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/targetmy`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'targetmy'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install targetmy
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/targetmy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
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 "targetmy"
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
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
data/lib/targetmy.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "watir"
2
+ require "watir-webdriver"
3
+ require "ostruct"
4
+ require 'ostruct'
5
+ require 'json'
6
+
7
+ module Targetmy
8
+ def self.root
9
+ Pathname.new(File.expand_path('../..',__FILE__))
10
+ end
11
+ end
12
+
13
+ require "targetmy/version"
14
+ require "targetmy/robot"
15
+ require "targetmy/config"
16
+ require "targetmy/exceptions"
17
+ require "targetmy/config/site/teaser"
18
+ require "targetmy/config/site/mobile"
@@ -0,0 +1,29 @@
1
+ require 'targetmy/config/site'
2
+ require 'ostruct'
3
+
4
+ module Targetmy
5
+ class Config
6
+ attr_reader :items
7
+
8
+ SUPPORTED_ADV_TYPES = [:site]
9
+
10
+ def initialize(config)
11
+ @items = []
12
+
13
+ parse config
14
+ end
15
+
16
+ def parse(config)
17
+ config = config.is_a?(Hash) ? [config] : config
18
+ config.each do |cnf|
19
+ if SUPPORTED_ADV_TYPES.include? cnf[:type].to_sym
20
+ type = cnf[:type].to_s.capitalize
21
+ klass = Object.const_get("Targetmy::Config::#{type}")
22
+ @items << klass.new(cnf)
23
+ else
24
+ raise Targetmy::UnsupportedKey.new(cnf[:type].to_sym)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ module Targetmy
2
+ class Config
3
+ class Site
4
+ attr_reader :type, :link, :adv_products
5
+
6
+ REQUIRED_KEYS = [:type, :link, :adv_products]
7
+ SUPPORTED_KEYS = [:type, :link, :adv_products]
8
+ SUPPORTED_ADV_PRODUCTS = [:teaser]
9
+
10
+ def initialize(config)
11
+ parse config
12
+ end
13
+
14
+ def parse(config)
15
+ config_required_items = REQUIRED_KEYS & config.keys
16
+ raise Targetmy::MissingRequiredKeys if config_required_items.length != REQUIRED_KEYS.length
17
+
18
+ SUPPORTED_KEYS.each do |key|
19
+ next unless config.has_key?(key)
20
+
21
+ case key
22
+ when :adv_products
23
+ @adv_products = []
24
+ parse_adv_products config[key]
25
+ else
26
+ instance_variable_set("@#{key}", config[key])
27
+ end
28
+ end
29
+ end
30
+
31
+ def parse_adv_products(prods)
32
+ adv_products = prods.is_a?(Hash) ? [prods] : prods
33
+ adv_products.each do |prod|
34
+ if prod.has_key?(:type) && SUPPORTED_ADV_PRODUCTS.include?(prod[:type].to_sym)
35
+ type = prod[:type].to_s.capitalize
36
+ klass = Object.const_get("Targetmy::Config::Site::#{type}")
37
+
38
+ @adv_products << klass.new(prod)
39
+ else
40
+ raise Targetmy::MissingRequiredKey.new(:type)
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ module Targetmy
2
+ class Config
3
+ class Site
4
+ class Mobile
5
+
6
+ def initialize(config)
7
+ parse config
8
+ end
9
+
10
+ def parse(config)
11
+
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ module Targetmy
2
+ class Config
3
+ class Site
4
+ class Teaser
5
+ attr_reader :type, :campaign_name, :ads
6
+
7
+ SUPPORTED_KEYS = [:type, :campaign_name, :ads]
8
+ SUPPORTED_ADS_KEYS = [:title, :text, :image]
9
+ REQUIRED_KEYS = [:ads, :type, :campaign_name]
10
+ REQUIRED_ADS_KEYS = [:title, :text, :image]
11
+
12
+ def initialize(config)
13
+ parse config
14
+ end
15
+
16
+ def parse(config)
17
+ config_required_items = REQUIRED_KEYS & config.keys
18
+ raise Targetmy::MissingRequiredKeys if config_required_items.length != REQUIRED_KEYS.length
19
+
20
+ SUPPORTED_KEYS.each do |key|
21
+ next unless config.has_key?(key)
22
+
23
+ case key
24
+ when :ads
25
+ @ads = []
26
+ parse_ads config[key]
27
+ else
28
+ instance_variable_set("@#{key}", config[key])
29
+ end
30
+ end
31
+ end
32
+
33
+ def parse_ads(ads)
34
+ ads = ads.is_a?(Hash) ? [ads] : ads
35
+
36
+ ads.each do |ad|
37
+ ad_obj = OpenStruct.new
38
+
39
+ ad_required_items = REQUIRED_ADS_KEYS & ad.keys
40
+ raise Targetmy::MissingRequiredKeys if ad_required_items.length != REQUIRED_ADS_KEYS.length
41
+
42
+ SUPPORTED_ADS_KEYS.each do |key|
43
+ next unless ad.has_key?(key)
44
+
45
+ ad_obj["#{key}"] = ad[key]
46
+ end
47
+
48
+ @ads << ad_obj
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ module Targetmy
2
+
3
+ class Error < Exception
4
+ end
5
+
6
+ class MissingRequiredKey < Error
7
+ def initialize(key)
8
+ super("Missing required key: #{key}")
9
+ end
10
+ end
11
+
12
+ class MissingRequiredKeys < Error
13
+ def initialize
14
+ super("Missing required keys")
15
+ end
16
+ end
17
+
18
+ class UnsupportedKey < Error
19
+ def initialize(key)
20
+ super("Unsupported key : #{key}")
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,126 @@
1
+ module Targetmy
2
+ class Robot
3
+
4
+ LOGIN_URL = 'https://account.my.com/login/'
5
+ CAMPAIGNS_URL = 'https://target.my.com/ads/campaigns/'
6
+ CAMPAIGNS_CREATE_URL = 'https://target.my.com/ads/create/'
7
+
8
+ ADV_TYPES_INDEXES = { site: 0, game: 1}
9
+ ADV_PROD_INDEXES = { teaser: 0, mobile: 1 }
10
+
11
+ def self.create(opts)
12
+ new(opts)
13
+ end
14
+
15
+ def initialize(opts)
16
+ @driver = opts.has_key?(:driver) ? opts[:driver] : :chrome
17
+ @config_raw = opts.has_key?(:config) ? opts[:config] : []
18
+
19
+ puts "create config"
20
+ @config = Targetmy::Config.new @config_raw
21
+ # OR
22
+ # @config = OpenStruct.new(items: JSON.parse(config.to_json, object_class: OpenStruct))
23
+ end
24
+
25
+ def start(email, password)
26
+ puts "start"
27
+
28
+ @browser = Watir::Browser.new @driver
29
+
30
+ if login(email, password)
31
+ create_campaign
32
+ end
33
+ end
34
+
35
+ def create_campaign
36
+ puts "create campaign"
37
+ # Watir::Wait.until { @browser.link(:css, ".campaign-toolbar .campaign-toolbar__create-button").present? }
38
+ # @browser.link(:css, ".campaign-toolbar .campaign-toolbar__create-button").click
39
+ # @browser.goto CAMPAIGNS_CREATE_URL
40
+ begin
41
+ @browser.goto CAMPAIGNS_URL
42
+
43
+ @config.items.each do |config|
44
+ click_create_campaign_btn
45
+ setup_adv_item config
46
+
47
+ Watir::Wait.until { @browser.div(:css, ".js-pacs-wrapper").present? }
48
+ @adv_prod_index = nil
49
+ config.adv_products.each do |prod|
50
+ click_product_btn prod
51
+
52
+ Watir::Wait.until { @browser.div(:css, ".banner-form").present? }
53
+ prod.ads.each do |ad|
54
+ create_ad ad
55
+ end
56
+
57
+ # @browser.text_field(:css, ".js-campaign-name").set(prod.campaign_name)
58
+ # @browser.div(:css, ".create-page__main-button").click
59
+ set_campaign_name prod
60
+ click_finish_campaign_btn
61
+ end
62
+
63
+ end
64
+
65
+ ensure
66
+ @browser.close
67
+ end
68
+ end
69
+
70
+ def set_campaign_name prod
71
+ @browser.text_field(:css, ".js-campaign-name").set(prod.campaign_name)
72
+ end
73
+
74
+ def click_finish_campaign_btn
75
+ @browser.div(:css, ".create-page__main-button").click
76
+ end
77
+
78
+ def create_ad ad
79
+ @browser.text_field(:css, ".banner-form__input.js-text-value").set(ad.title)
80
+ @browser.textarea(:css, ".banner-form__input.js-text-value.banner-form__input_text-area").set(ad.text)
81
+ @browser.file_field(:css, ".banner-form__img-file.banner-form__input.js-image-value").set(ad.image)
82
+ Watir::Wait.until { @browser.button(:css, ".image-cropper__save").present? }
83
+ @browser.button(:css, ".image-cropper__save").click
84
+
85
+ Watir::Wait.until { @browser.button(:css, ".banner-form__save-button.js-banner-save").present? }
86
+ Watir::Wait.until { sleep 1 }
87
+ @browser.button(:css, ".banner-form__save-button.js-banner-save").click
88
+ end
89
+
90
+ def click_product_btn prod
91
+ if @adv_prod_index != ADV_PROD_INDEXES[prod.type.to_sym]
92
+ @adv_prod_index = ADV_PROD_INDEXES[prod.type.to_sym]
93
+ @browser.div(css: ".pac-item._gray-block", index: @adv_prod_index).click
94
+ end
95
+ end
96
+
97
+ def setup_adv_item config
98
+ Watir::Wait.until { @browser.div(:css, ".product-types.js-product-types-wrap").present? }
99
+ @adv_type_index = ADV_TYPES_INDEXES[config.type.to_sym]
100
+ @browser.div(css: ".product-types__item", index: @adv_type_index).click
101
+ @browser.text_field(:css, ".base-setting-my__main-url__input.js-main-url-input").set(config.link)
102
+ end
103
+
104
+ def click_create_campaign_btn
105
+ Watir::Wait.until { @browser.link(:css, ".campaign-toolbar .campaign-toolbar__create-button").present? }
106
+ @browser.link(:css, ".campaign-toolbar .campaign-toolbar__create-button").click
107
+ end
108
+
109
+ def login(email, password)
110
+ puts "login"
111
+
112
+ @browser.goto LOGIN_URL
113
+
114
+ @browser.text_field(:id, "email").set(email)
115
+ @browser.text_field(:id, "password").set(password)
116
+ @browser.form(:id,'login_form').submit
117
+
118
+ if @browser.div(css: ".formMsg.js_form_msg.js_form_msg").present?
119
+ puts "Wrong login or password!"
120
+ @browser.close
121
+ end
122
+
123
+ true
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,3 @@
1
+ module Targetmy
2
+ VERSION = "0.1.0"
3
+ end
data/targetmy.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'targetmy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "targetmy"
8
+ spec.version = Targetmy::VERSION
9
+ spec.authors = ["dimag"]
10
+ spec.email = ["dmitry.gvl@gmail.com"]
11
+
12
+ spec.summary = %q{Target.my.com}
13
+ spec.description = %q{Target.my.com}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+
26
+ spec.add_development_dependency "byebug", '~> 9.0', '>= 9.0.5'
27
+
28
+ spec.add_runtime_dependency "watir", '~> 5.0'
29
+ spec.add_runtime_dependency "watir-webdriver", '~> 0.9.1'
30
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: targetmy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dimag
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-29 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.0'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 9.0.5
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '9.0'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 9.0.5
75
+ - !ruby/object:Gem::Dependency
76
+ name: watir
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: watir-webdriver
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.9.1
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.1
103
+ description: Target.my.com
104
+ email:
105
+ - dmitry.gvl@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - ".travis.yml"
113
+ - Gemfile
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - bin/console
118
+ - bin/setup
119
+ - lib/targetmy.rb
120
+ - lib/targetmy/config.rb
121
+ - lib/targetmy/config/site.rb
122
+ - lib/targetmy/config/site/mobile.rb
123
+ - lib/targetmy/config/site/teaser.rb
124
+ - lib/targetmy/exceptions.rb
125
+ - lib/targetmy/robot.rb
126
+ - lib/targetmy/version.rb
127
+ - targetmy.gemspec
128
+ homepage: ''
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.5.1
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Target.my.com
152
+ test_files: []