japonica 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: 4bf2590f2d9732fd832f8cc53571ea2a9bc04294
4
+ data.tar.gz: 6d1bac5d8aac3086b4a0502e8be3169a2e0f747f
5
+ SHA512:
6
+ metadata.gz: 974760745c2775065fd4cae0add8df02cc9bfe6c6b6683242144db125992cf7516339262936cb700324e09ec66edb34bcecf83ddbb7e5f2513c427bcda32c417
7
+ data.tar.gz: b4ca13593240fb0bd17416040e3c7b406b2de8928ad793de6f5dd06e401c73fcdb0c9502cfaf14a4d9260558e2067d39707606ecf8a3bd6388084d5b7b66d09f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in japonica.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ryands
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Japonica
2
+
3
+ A cli tool for generating order email text from auction site links. Currently
4
+ only Yahoo! Japan and Mbok are supported.
5
+
6
+ This utility will populate the fields of the order form with data scraped from the
7
+ content of the provided url.
8
+
9
+ ## Installation
10
+
11
+ $ git clone git://github.com/ryands/japonica.git japonica
12
+ $ cd japonica/
13
+ $ bundle install
14
+ $ rake install
15
+
16
+ ## Usage
17
+
18
+ $ japonica order <yahoo or mbok auction link> <max_bid in yen> [bid type]
19
+
20
+ The [bid type] can be one of: `bid`, `snipe`, or `bin` (buy-it-now).
21
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/japonica ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'japonica/cli'
4
+ Japonica::CLI.start(ARGV)
data/japonica.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'japonica/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "japonica"
8
+ spec.version = Japonica::VERSION
9
+ spec.authors = ["ryands"]
10
+ spec.email = ["ryan@ryands.org"]
11
+ spec.description = %q{CLI tool for generating email orderforms for yahoo and mbok auctions with japonica}
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'thor'
22
+ spec.add_dependency 'nokogiri', '~> 1.6'
23
+ spec.add_dependency 'httparty'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,68 @@
1
+ # Represents an Auction
2
+
3
+ require 'httparty'
4
+ require 'nokogiri'
5
+
6
+ module Japonica
7
+ class Auction
8
+ attr_accessor :url
9
+ attr_accessor :item_name
10
+ attr_accessor :seller_id
11
+ attr_accessor :current_price
12
+ attr_accessor :max_bid
13
+
14
+ def is_mbok?
15
+ url =~ /mbok\.jp/i
16
+ end
17
+
18
+ def is_yahoo?
19
+ url =~ /yahoo\.co\.jp/i
20
+ end
21
+
22
+ # Load auction from url
23
+ def self.load_url(url)
24
+ auction = Auction.new
25
+ auction.url = url
26
+
27
+ html = fetch_html url
28
+
29
+ if auction.is_mbok?
30
+ load_mbok html, auction
31
+ elsif auction.is_yahoo?
32
+ load_yahoo html, auction
33
+ else
34
+ nil
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def self.fetch_html(url)
41
+ response = HTTParty.get url
42
+ html = response.body
43
+ Nokogiri::HTML html
44
+ end
45
+
46
+ def self.load_mbok(noko, auction)
47
+ item_name = noko.at_css 'h1.title[itemprop=name]'
48
+ seller_id = noko.at_css 'p.owner-name a'
49
+ current_price = noko.at_css 'span[itemprop=Price]'
50
+
51
+ auction.item_name = item_name.text unless item_name.nil?
52
+ auction.seller_id = seller_id.text unless seller_id.nil?
53
+ auction.current_price = current_price.text unless current_price.nil?
54
+ auction
55
+ end
56
+
57
+ def self.load_yahoo(noko, auction)
58
+ item_name = noko.at_css "h1[property='auction:Title']"
59
+ seller_id = noko.at_css "b[property='auction:SellerID']"
60
+ current_price = noko.at_css "p[property='auction:Price']"
61
+
62
+ auction.item_name = item_name.text unless item_name.nil?
63
+ auction.seller_id = seller_id.text unless seller_id.nil?
64
+ auction.current_price = current_price.text unless current_price.nil?
65
+ auction
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+
2
+ require 'erb'
3
+ require 'thor'
4
+ require 'japonica/auction'
5
+
6
+
7
+ module Japonica
8
+ class CLI < Thor
9
+
10
+ desc "order URL MAX_BID BID_TYPE", "Creates an order form using the auction url and max bid.\nBID_TYPE can be: [instant|bid, bin (buy it now), snipe]"
11
+ def order(url, max='xxxx', type=:instant)
12
+ @auction = Japonica::Auction.load_url url
13
+ @max_bid = max
14
+ @bid_type = type_name type.to_sym
15
+
16
+ # doesn't use thor's template() since i don't want to output to a file
17
+ puts ERB.new(File.read(File.join(template_path, 'orderform.tt'))).result(binding)
18
+ end
19
+
20
+ private
21
+
22
+ def template_path
23
+ File.join(File.dirname(__FILE__), '..', 'templates')
24
+ end
25
+
26
+ def type_name (type)
27
+ case type
28
+ when :instant, :bid
29
+ 'Instant Bid'
30
+ when :bin, :now
31
+ 'Buy It Now'
32
+ when :snipe
33
+ 'Snipe Bid'
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Japonica
2
+ VERSION = "0.1.0"
3
+ end
data/lib/japonica.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "japonica/version"
2
+
3
+ module Japonica
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,18 @@
1
+ [ Auctions / Shopping Order Form ]
2
+
3
+ Seller ID : <%= @auction.seller_id %>
4
+ Item Name : <%= @auction.item_name %>
5
+ Auction ID / Item URL : <%= @auction.url %>
6
+ Max bid Price : <%= @max_bid %> yen
7
+ Bidding Options : <%= @bid_type %>
8
+
9
+ <% if @include_billing %>
10
+ Payment : ( Credit Card/Bank through PayPal )
11
+ Shipping Options : EMS / Registered Airmail
12
+ PayPal Account :
13
+ PayPal Confirmed Shipping Name and Address :
14
+ <% end %>
15
+
16
+ <% unless @note.nil? %>
17
+ note : <%= @note %>
18
+ <% end %>
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: japonica
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ryands
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
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
+ description: CLI tool for generating email orderforms for yahoo and mbok auctions
84
+ with japonica
85
+ email:
86
+ - ryan@ryands.org
87
+ executables:
88
+ - japonica
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/japonica
98
+ - japonica.gemspec
99
+ - lib/japonica.rb
100
+ - lib/japonica/auction.rb
101
+ - lib/japonica/cli.rb
102
+ - lib/japonica/version.rb
103
+ - lib/templates/orderform.tt
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.0
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: CLI tool for generating email orderforms for yahoo and mbok auctions with
128
+ japonica
129
+ test_files: []