dieselup 1.0.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: d02bead4937b5c120fa4cb9aa20bc862854f6c81
4
+ data.tar.gz: d84b4578e89fc72b644da346369fad2a37f6caab
5
+ SHA512:
6
+ metadata.gz: 13470bfb795266768a76a59565cecbb035065d9b398feed614d0915c60fff87b27bb74760ccb7a6a25c6e5bc127aa162e45f463c6a529b9a5436380d76ab3198
7
+ data.tar.gz: 1daa8de6051af0bc5a3527b5235e329125f058bfaf5ec8d5f339b411d9844de7d7caabbca982a2c10d5e0a282f42e69d2bbaebbd608d5f09251c6896c9c93a17
data/.env.dist ADDED
@@ -0,0 +1,2 @@
1
+ USERNAME=""
2
+ PASSWORD=""
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
+ *.gem
11
+ .env
12
+ *.html
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
6
+ - 2.2.0
7
+ env:
8
+ global:
9
+ - secure: AtVYNnfo2JaqXAe/xXwzCzgJIvWF5D5CiEeu4nhT9fA9HHuxUUyL4SEoMXcdmfdm/ECUucj0LL/Feu7J6GAwDaetLlNqb3zj27CLk89cbAuBoGmU/y4LqALflRm2s7CMNTry13V/uo/gXtdAXN56lEj0+V7OJVrDLtz6OHryvFKjClSJmsyeDmFOLDHpQ+ISnhEFfZ4dZ6GRlPuVs0Gr5GdKL9QFg8WtWZhpacLT87IHyoxVXiOX8x0Egcrgc2UxhJLZ9VHb5du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HSqZVf6wawD4Yn/4n9Xd95TnGdvcgU=
11
+ before_install:
12
+ - gem install bundler -v 1.7 --no-ri --no-rdoc
13
+ - cp .env.dist .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dieselup.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kairat Jenishev
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,39 @@
1
+ # Dieselup
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/dieselup`. 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 'dieselup'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dieselup
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 `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` to 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
+ 1. Fork it ( https://github.com/[my-github-username]/dieselup/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'dieselup'
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/dieselup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dieselup'
4
+
5
+ base = Dieselup::Base.new
6
+ base.up!
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/dieselup.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dieselup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dieselup'
8
+ spec.version = Dieselup::VERSION
9
+ spec.author = 'Kairat Jenishev'
10
+ spec.email = 'kairat.jenishev@gmail.com'
11
+
12
+ spec.summary = 'DieselUp!'
13
+ spec.description = 'Lift up your topic to the top in Diesel Forum'
14
+ spec.homepage = 'https://github.com/xcopy/dieselup-ruby'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split($\)
18
+ spec.bindir = 'bin'
19
+ spec.executables = ['dieselup']
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 1.9.3'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'dotenv', '~> 2.1'
27
+ spec.add_development_dependency 'rspec', '~> 3.4'
28
+
29
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
30
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6'
31
+ end
@@ -0,0 +1,97 @@
1
+ module Dieselup
2
+ class Base
3
+ attr_accessor :cookies
4
+
5
+ def initialize
6
+ @cookies = []
7
+ end
8
+
9
+ def up!
10
+ login
11
+ post
12
+ end
13
+
14
+ def login
15
+ response = request(Dieselup::Url::BASE)
16
+ document = Nokogiri::HTML(response.body)
17
+
18
+ if document.css('div#userlinks').empty?
19
+ url = Dieselup::Url.get(act: 'Login', CODE: '01')
20
+ params = {UserName: ENV['USERNAME'], PassWord: ENV['PASSWORD']}
21
+ response = request(url, 'POST', params)
22
+ end
23
+
24
+ response
25
+ end
26
+
27
+ def post
28
+ raise ArgumentError, 'Not enough arguments' unless ARGV.any?
29
+
30
+ response = request(Dieselup::Url.get(showtopic: ARGV.first))
31
+ document = Nokogiri::HTML(response.body)
32
+
33
+ delete_links = document.css('//a[@href*="javascript:delete_post"]').map { |link|
34
+ link[:href].match(/'([^']+)/).to_a.last
35
+ }
36
+
37
+ if delete_links.any?
38
+ request(delete_links.last)
39
+ end
40
+
41
+ params = {Post: 'UP'}
42
+
43
+ hidden_inputs = document.css('//form[@name*="REPLIER"]/input[@type*="hidden"]')
44
+ hidden_inputs.each do |input|
45
+ params[input[:name]] = input[:value]
46
+ end
47
+
48
+ request(Dieselup::Url::BASE, 'POST', params)
49
+ end
50
+
51
+ def request(url, method = 'GET', params = {})
52
+ uri = URI(url)
53
+
54
+ http = Net::HTTP.new(uri.host, uri.port)
55
+ http.use_ssl = uri.scheme == 'https'
56
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
57
+
58
+ if method.upcase == 'POST'
59
+ request = Net::HTTP::Post.new(uri.request_uri)
60
+ request.set_form_data(params)
61
+ else
62
+ request = Net::HTTP::Get.new(uri.request_uri)
63
+ end
64
+
65
+ unless @cookies.empty?
66
+ request['Cookie'] = @cookies.join(';')
67
+ end
68
+
69
+ response = http.request(request)
70
+
71
+ document = Nokogiri::HTML(response.body)
72
+
73
+ errors = document.xpath('//div[@class="errorwrap"]/p')
74
+
75
+ raise StandardError, errors.first.text if errors.any?
76
+
77
+ cookies = response.get_fields('set-cookie')
78
+ cookies.each do |cookie|
79
+ @cookies.push(cookie.split('; ').first)
80
+ end
81
+
82
+ response
83
+ end
84
+
85
+ =begin
86
+ def request(url, method = 'GET', params = {})
87
+ uri = URI.parse(url)
88
+
89
+ if method.upcase == 'POST'
90
+ Net::HTTP.post_form(uri, params)
91
+ else
92
+ Net::HTTP.get_response(uri)
93
+ end
94
+ end
95
+ =end
96
+ end
97
+ end
@@ -0,0 +1,11 @@
1
+ require 'active_support/core_ext/object/to_param'
2
+
3
+ module Dieselup
4
+ class Url
5
+ BASE = 'https://diesel.elcat.kg/index.php'
6
+
7
+ def self.get(query = {})
8
+ "#{BASE}?#{query.to_param}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Dieselup
2
+ VERSION = '1.0.0'
3
+ end
data/lib/dieselup.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'nokogiri'
2
+ require 'dotenv'
3
+
4
+ module Dieselup
5
+ autoload :Base, 'dieselup/base'
6
+ autoload :Url, 'dieselup/url'
7
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dieselup do
4
+ before(:all) do
5
+ @base = Dieselup::Base.new
6
+ end
7
+
8
+ it 'has a version number' do
9
+ expect(Dieselup::VERSION).not_to be_nil
10
+ end
11
+
12
+ it 'has environment .env file' do
13
+ expect(File.exist?('.env')).to be_truthy
14
+ expect(ENV['USERNAME']).to_not be_nil
15
+ expect(ENV['PASSWORD']).to_not be_nil
16
+ end
17
+
18
+ context Dieselup::Url do
19
+ it 'returns correct URLs' do
20
+ expect(Dieselup::Url::BASE).to eq 'https://diesel.elcat.kg/index.php'
21
+ expect(Dieselup::Url.get(showtopic: 1)).to eq 'https://diesel.elcat.kg/index.php?showtopic=1'
22
+ end
23
+ end
24
+
25
+ context Dieselup::Base do
26
+ it 'should have empty cookies' do
27
+ expect(@base.cookies).to be_empty
28
+ end
29
+
30
+ it 'should login successfully' do
31
+ response = @base.login
32
+ document = Nokogiri::HTML(response.body)
33
+
34
+ expect(response.code).to eq '200'
35
+ expect(document.at("p:contains(#{ENV['USERNAME']})")).to_not be_nil
36
+ end
37
+
38
+ it 'should send GET request and get successful response' do
39
+ response = @base.request(Dieselup::Url::BASE)
40
+ document = Nokogiri::HTML(response.body)
41
+
42
+ expect(response.code).to eq '200'
43
+ expect(document.at("a:contains(#{ENV['USERNAME']})")).to_not be_nil
44
+ end
45
+
46
+ it 'should raise error' do
47
+ @base.cookies = []
48
+ ENV['USERNAME'] = nil
49
+ ARGV.clear
50
+
51
+ expect { @base.request(Dieselup::Url.get(showtopic: 1)) }.to raise_error(StandardError)
52
+ expect { @base.post }.to raise_error(ArgumentError)
53
+ expect { @base.login }.to raise_error(StandardError)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'dieselup'
3
+ Dotenv.load('.env')
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dieselup
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kairat Jenishev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-21 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ description: Lift up your topic to the top in Diesel Forum
98
+ email: kairat.jenishev@gmail.com
99
+ executables:
100
+ - dieselup
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".env.dist"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/dieselup
114
+ - bin/setup
115
+ - dieselup.gemspec
116
+ - lib/dieselup.rb
117
+ - lib/dieselup/base.rb
118
+ - lib/dieselup/url.rb
119
+ - lib/dieselup/version.rb
120
+ - spec/dieselup_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: https://github.com/xcopy/dieselup-ruby
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.9.3
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.6
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: DieselUp!
146
+ test_files: []