rwsc 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +21 -0
- data/README.rdoc +3 -0
- data/Rakefile +116 -0
- data/lib/rwsc.rb +14 -0
- data/lib/rwsc/arg.rb +14 -0
- data/lib/rwsc/arg_error.rb +9 -0
- data/lib/rwsc/config.rb +24 -0
- data/lib/rwsc/const.rb +12 -0
- data/lib/rwsc/item_search.rb +78 -0
- data/lib/rwsc/operation.rb +9 -0
- data/lib/rwsc/result_item.rb +21 -0
- data/lib/rwsc/status.rb +19 -0
- data/lib/rwsc/status_error.rb +9 -0
- data/lib/rwsc/utils/string_utils.rb +13 -0
- data/lib/rwsc/version.rb +11 -0
- data/lib/rwsc/web/web_client.rb +142 -0
- data/spec/matchers/utils/be_underscore_of.rb +18 -0
- data/spec/rwsc/arg_error_spec.rb +16 -0
- data/spec/rwsc/config_spec.rb +29 -0
- data/spec/rwsc/const_spec.rb +10 -0
- data/spec/rwsc/item_search_spec.rb +36 -0
- data/spec/rwsc/utils/string_utils_spec.rb +30 -0
- data/spec/rwsc/version_spec.rb +13 -0
- data/spec/spec_helper.rb +6 -0
- metadata +106 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009 byplayer and takayoshi kohayakawa
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
require "rtask"
|
7
|
+
|
8
|
+
|
9
|
+
# return rspec options
|
10
|
+
def set_speck_opt(t)
|
11
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
12
|
+
t.spec_opts = ['--color']
|
13
|
+
t.warning = true
|
14
|
+
end
|
15
|
+
|
16
|
+
# rspec tasks
|
17
|
+
desc "Run all specs"
|
18
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
19
|
+
set_speck_opt t
|
20
|
+
end
|
21
|
+
|
22
|
+
# rspec coverate tasks
|
23
|
+
desc "Run rcov"
|
24
|
+
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
25
|
+
set_speck_opt t
|
26
|
+
t.rcov = true
|
27
|
+
end
|
28
|
+
|
29
|
+
# gem tasks
|
30
|
+
PKG_FILES = FileList[
|
31
|
+
'[A-Z]*',
|
32
|
+
'bin/**/*',
|
33
|
+
'lib/**/*.rb',
|
34
|
+
'test/**/*.rb',
|
35
|
+
'doc/**/*',
|
36
|
+
'spec/**/*.rb',
|
37
|
+
]
|
38
|
+
|
39
|
+
VER_NUM = `ruby -Ilib -e 'require "rwsc/version"; puts Rwsc::VERSION::STRING'`
|
40
|
+
|
41
|
+
if VER_NUM =~ /([0-9.]+)$/
|
42
|
+
CURRENT_VERSION = $1
|
43
|
+
else
|
44
|
+
CURRENT_VERSION = "0.0.0"
|
45
|
+
end
|
46
|
+
|
47
|
+
class RTask
|
48
|
+
# overwrite init_spec
|
49
|
+
# get version automaticaly .
|
50
|
+
# get package files automaticaly .
|
51
|
+
def init_spec
|
52
|
+
::Gem::Specification.new do |s|
|
53
|
+
s.name = "rwsc"
|
54
|
+
s.rubyforge_project = s.name
|
55
|
+
s.version = CURRENT_VERSION
|
56
|
+
s.summary = "Rakuten Webservice client library"
|
57
|
+
s.description = <<-EOS
|
58
|
+
Rakuten Webservice client library
|
59
|
+
EOS
|
60
|
+
s.authors = ["byplayer", "takayoshi kohayakawa"]
|
61
|
+
s.email = ["byplayer100@gmail.com",
|
62
|
+
"takayoshi.kohayakawa@mail.rakuten.co.jp"]
|
63
|
+
s.homepage = "http://wiki.github.com/byplayer/rwsc"
|
64
|
+
|
65
|
+
s.files = PKG_FILES.to_a
|
66
|
+
|
67
|
+
s.require_path = 'lib'
|
68
|
+
|
69
|
+
s.has_rdoc = true
|
70
|
+
s.rdoc_options << '--line-numbers' << '--inline-source' <<
|
71
|
+
"--main" << "README.rdoc" << "-c UTF-8"
|
72
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
73
|
+
|
74
|
+
s.add_dependency('nokogiri')
|
75
|
+
s.add_dependency('rspec')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# overwrite
|
80
|
+
# get package files automaticaly
|
81
|
+
def manifest
|
82
|
+
PKG_FILES.to_a
|
83
|
+
end
|
84
|
+
|
85
|
+
def tgz
|
86
|
+
base_name = "#{@package}-#{@version}"
|
87
|
+
tgz_name = "#{base_name}.tgz"
|
88
|
+
|
89
|
+
to_base = File.expand_path(File.join(File.dirname(__FILE__),"#{base_name}"))
|
90
|
+
FileUtils.mkdir_p(to_base)
|
91
|
+
|
92
|
+
manifest.each do |fname|
|
93
|
+
to_fname = File.join(to_base, fname)
|
94
|
+
FileUtils.mkdir_p(File.dirname(to_fname))
|
95
|
+
FileUtils.copy_entry(fname, to_fname)
|
96
|
+
end
|
97
|
+
|
98
|
+
sh "tar -c -z -f #{tgz_name} #{base_name}"
|
99
|
+
|
100
|
+
FileUtils.remove_entry(to_base)
|
101
|
+
end
|
102
|
+
|
103
|
+
def rdoc
|
104
|
+
require 'rake/rdoctask'
|
105
|
+
Rake::RDocTask.new do |doc|
|
106
|
+
doc.title = "#{@package}-#{@version} documentation"
|
107
|
+
doc.main = "README.rdoc"
|
108
|
+
doc.rdoc_files.include(manifest)
|
109
|
+
doc.options << "--line-numbers" << "--inline-source" << "-c UTF-8"
|
110
|
+
yield doc if block_given?
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# create rtask tasks
|
116
|
+
RTask.new
|
data/lib/rwsc.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rwsc/config'
|
4
|
+
require 'rwsc/version'
|
5
|
+
require 'rwsc/const'
|
6
|
+
require 'rwsc/utils/string_utils'
|
7
|
+
require 'rwsc/operation'
|
8
|
+
require 'rwsc/arg_error'
|
9
|
+
require 'rwsc/status_error'
|
10
|
+
require 'rwsc/result_item'
|
11
|
+
require 'rwsc/arg'
|
12
|
+
require 'rwsc/status'
|
13
|
+
require 'rwsc/item_search'
|
14
|
+
|
data/lib/rwsc/arg.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Rwsc
|
4
|
+
# = this class is Rakuten Webservice result arg item .
|
5
|
+
class Arg
|
6
|
+
attr_accessor :key, :value, :result
|
7
|
+
|
8
|
+
def initialize(key, value, result)
|
9
|
+
self.key = key
|
10
|
+
self.value = value
|
11
|
+
self.result = result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rwsc/config.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Rwsc
|
4
|
+
class Config
|
5
|
+
def self.proxy_host=(proxy_host)
|
6
|
+
@@proxy_host = proxy_host
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.proxy_host
|
10
|
+
@@proxy_host
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.proxy_port=(proxy_port)
|
14
|
+
@@proxy_port = proxy_port
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.proxy_port
|
18
|
+
@@proxy_port
|
19
|
+
end
|
20
|
+
|
21
|
+
@@proxy_host = nil
|
22
|
+
@@proxy_port = nil
|
23
|
+
end
|
24
|
+
end
|
data/lib/rwsc/const.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rwsc/web/web_client'
|
3
|
+
|
4
|
+
module Rwsc
|
5
|
+
# = ItemSearch class
|
6
|
+
# this class is ItemSearch API wrapper .
|
7
|
+
class ItemSearch < ResultItem
|
8
|
+
# == find item .
|
9
|
+
def self.find(opts)
|
10
|
+
if opts.nil?
|
11
|
+
raise ArgError.new('no options')
|
12
|
+
end
|
13
|
+
|
14
|
+
self.must_items.each do |item|
|
15
|
+
unless opts.include? item
|
16
|
+
raise ArgError.new("#{item.to_s} needed")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.each do |key, val|
|
21
|
+
unless accept_items.include? key
|
22
|
+
raise ArgError.new("#{key.to_s} is invalid option")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
self.rws_call(opts.merge(self.add_rwsc_opts))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
MUST_ITEMS = [:developerId]
|
31
|
+
|
32
|
+
def self.must_items
|
33
|
+
MUST_ITEMS
|
34
|
+
end
|
35
|
+
|
36
|
+
ACCEPT_ITEMS = [
|
37
|
+
:developerId,
|
38
|
+
:affiliateId,
|
39
|
+
:keyword,
|
40
|
+
:shopCode,
|
41
|
+
:genreId,
|
42
|
+
:catalogCode,
|
43
|
+
:hits,
|
44
|
+
:page,
|
45
|
+
:sort,
|
46
|
+
:minPrice,
|
47
|
+
:maxPrice,
|
48
|
+
:availability,
|
49
|
+
:field,
|
50
|
+
:carrier,
|
51
|
+
:imageFlag,
|
52
|
+
:orFlag,
|
53
|
+
:NGKeyword,
|
54
|
+
:genreInformationFlag,
|
55
|
+
:purchaseType,
|
56
|
+
]
|
57
|
+
|
58
|
+
def self.accept_items
|
59
|
+
ACCEPT_ITEMS
|
60
|
+
end
|
61
|
+
|
62
|
+
# == Additional Rakuten web service call option
|
63
|
+
ADD_RWSC_OPTS = {
|
64
|
+
:version => CONST::API_VERSION,
|
65
|
+
:operation => OPERATION::ITEM_SEARCH,
|
66
|
+
}
|
67
|
+
|
68
|
+
# == get additional Rakuten web service call option
|
69
|
+
def self.add_rwsc_opts
|
70
|
+
ADD_RWSC_OPTS
|
71
|
+
end
|
72
|
+
|
73
|
+
# == Rakuten web service call function
|
74
|
+
def self.rws_call(opts)
|
75
|
+
Rwsc::Web::WebClient.get_result(opts)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Rwsc
|
4
|
+
|
5
|
+
# = this class is ResultItem base class .
|
6
|
+
class ResultItem
|
7
|
+
def method_missing(name, *args)
|
8
|
+
@data_hash ||= {}
|
9
|
+
|
10
|
+
method_name = name.to_s
|
11
|
+
|
12
|
+
if method_name =~ /(.*)=$/
|
13
|
+
@data_hash[$1] = *args
|
14
|
+
elsif args.nil? || args.empty?
|
15
|
+
return @data_hash[method_name]
|
16
|
+
end
|
17
|
+
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rwsc/status.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Rwsc
|
4
|
+
# = this class is Rakuten Webservice result status item .
|
5
|
+
class Status
|
6
|
+
attr_accessor :status, :status_msg
|
7
|
+
|
8
|
+
SUCCESS = 'Success'
|
9
|
+
NOT_FOUND = 'NotFound'
|
10
|
+
SERVER_ERROR = 'ServerError'
|
11
|
+
CLIENT_ERROR = 'ClientError'
|
12
|
+
MAINTENANCE = 'Maintenance'
|
13
|
+
|
14
|
+
def initialize(status = nil, status_msg = nil)
|
15
|
+
self.status = status
|
16
|
+
self.status_msg = status_msg
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Rwsc
|
4
|
+
module Utils
|
5
|
+
module StringUtils
|
6
|
+
# The reverse of +camelize+. Makes an underscored, lowercase .
|
7
|
+
def self.underscore word
|
8
|
+
return word unless word =~ /[A-Z]/
|
9
|
+
word.gsub(/([a-z\d]+)([A-Z]+)/, '\1_\2').downcase
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/rwsc/version.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
module Rwsc
|
8
|
+
module Web
|
9
|
+
|
10
|
+
# = this class is Rakuten WebSearch web client .
|
11
|
+
class WebClient
|
12
|
+
# == this method call webservice api .
|
13
|
+
def self.get_result(opts)
|
14
|
+
WebClient.new.call_http(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
# == try proxy connect
|
18
|
+
# use proxy connect if set proxy configuration .
|
19
|
+
def call_http(opts)
|
20
|
+
uri = generate_uri(opts)
|
21
|
+
|
22
|
+
Net::HTTP.Proxy(Config.proxy_host,
|
23
|
+
Config.proxy_port).start(uri.host, uri.port) do |http|
|
24
|
+
res = http.get("#{uri.path}?#{uri.query}",
|
25
|
+
{'User-Agent' => Rwsc::CONST::USER_AGENT})
|
26
|
+
parse_result(Nokogiri::XML(res.body))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
# == generate uri object from opts .
|
32
|
+
def generate_uri(opts)
|
33
|
+
url = Rwsc::CONST::WS_URL + "?"
|
34
|
+
if opts
|
35
|
+
url += opts.map do |key, val|
|
36
|
+
"#{URI.escape(key.to_s)}=#{URI.escape(val.to_s)}"
|
37
|
+
end.join('&')
|
38
|
+
end
|
39
|
+
|
40
|
+
URI.parse(url)
|
41
|
+
end
|
42
|
+
|
43
|
+
# == parse xml items
|
44
|
+
def parse_result(doc)
|
45
|
+
@item_search = ItemSearch.new
|
46
|
+
parse_status(doc)
|
47
|
+
parse_args(doc)
|
48
|
+
parse_common_info(doc)
|
49
|
+
parse_items(doc)
|
50
|
+
|
51
|
+
@item_search
|
52
|
+
end
|
53
|
+
|
54
|
+
# == parse status
|
55
|
+
# if status is not success, this function raise
|
56
|
+
#
|
57
|
+
def parse_status(doc)
|
58
|
+
status = Status.new
|
59
|
+
status.status = first_item_content(doc, '/Response/header:Header/Status')
|
60
|
+
status.status_msg =
|
61
|
+
first_item_content(doc, '/Response/header:Header/StatusMsg')
|
62
|
+
@item_search.status = status
|
63
|
+
|
64
|
+
unless @item_search.status.status == Status::SUCCESS
|
65
|
+
raise StatusError.new("API Error(#{@item_search.status.status}):" +
|
66
|
+
"#{@item_search.status.status_msg}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# == parse ARG items
|
71
|
+
def parse_args(doc)
|
72
|
+
args = []
|
73
|
+
doc.xpath('/Response/header:Header/Args/Arg', doc.namespaces).each do |a|
|
74
|
+
args << Arg.new(a.attribute('key'),
|
75
|
+
a.attribute('value'),
|
76
|
+
a.content)
|
77
|
+
end
|
78
|
+
|
79
|
+
@item_search.args = args
|
80
|
+
end
|
81
|
+
|
82
|
+
# == parse common info
|
83
|
+
def parse_common_info(doc)
|
84
|
+
{
|
85
|
+
'count' => 'count',
|
86
|
+
'page' => 'page',
|
87
|
+
'first' => 'first',
|
88
|
+
'last' => 'last',
|
89
|
+
'hits'=> 'hits',
|
90
|
+
'carrier' => 'carrier',
|
91
|
+
'pageCount' => 'page_count',
|
92
|
+
}.each do |xml_tag, func|
|
93
|
+
@item_search.send("#{func}=",
|
94
|
+
first_item_content(doc,
|
95
|
+
"/Response/Body/itemSearch:ItemSearch/#{xml_tag}"))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# == parse items
|
100
|
+
def parse_items(doc)
|
101
|
+
items = []
|
102
|
+
|
103
|
+
doc.xpath('/Response/Body/itemSearch:ItemSearch/Items/Item',
|
104
|
+
doc.namespaces).each do |i|
|
105
|
+
item = ResultItem.new
|
106
|
+
|
107
|
+
i.children.each do |element|
|
108
|
+
|
109
|
+
item.send("#{Rwsc::Utils::StringUtils.underscore(element.name)}=",
|
110
|
+
element.content)
|
111
|
+
end
|
112
|
+
|
113
|
+
items << item
|
114
|
+
end
|
115
|
+
|
116
|
+
@item_search.items = items
|
117
|
+
end
|
118
|
+
|
119
|
+
# == get first item
|
120
|
+
# if item not exists, return nil
|
121
|
+
def first_item(doc, xpath)
|
122
|
+
items = doc.xpath(xpath, doc.namespaces)
|
123
|
+
if items && !items.empty?
|
124
|
+
return items.first
|
125
|
+
end
|
126
|
+
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
|
130
|
+
# == get first item content
|
131
|
+
# if item not exist, return nil
|
132
|
+
def first_item_content(doc, xpath)
|
133
|
+
item = first_item(doc, xpath)
|
134
|
+
if item
|
135
|
+
return item.content
|
136
|
+
end
|
137
|
+
|
138
|
+
nil
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Spec::Matchers.define :be_underscore_of do |expected|
|
2
|
+
match do |actual|
|
3
|
+
Rwsc::Utils::StringUtils::underscore(actual) == expected
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message_for_should do |actual|
|
7
|
+
"expected that #{actual} would be underscore of #{expected}"
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_for_should_not do |actual|
|
11
|
+
"expected that #{actual} would not be a underscore of #{expected}"
|
12
|
+
end
|
13
|
+
|
14
|
+
description do
|
15
|
+
"be a underscore of #{expected}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
3
|
+
'..', 'spec_helper'))
|
4
|
+
require 'rwsc/arg_error'
|
5
|
+
|
6
|
+
|
7
|
+
describe Rwsc::ArgError, "message method" do
|
8
|
+
subject { Rwsc::ArgError.new("my error msg").message }
|
9
|
+
|
10
|
+
it { should == "my error msg" }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Rwsc::ArgError, "to_s method" do
|
14
|
+
subject { Rwsc::ArgError.new("my error msg by to_s").to_s }
|
15
|
+
it { should == "my error msg by to_s" }
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
3
|
+
'..', 'spec_helper'))
|
4
|
+
require 'rwsc'
|
5
|
+
|
6
|
+
describe Rwsc::Config, "proxy_host" do
|
7
|
+
subject { Rwsc::Config.proxy_host }
|
8
|
+
|
9
|
+
it { should be_nil }
|
10
|
+
|
11
|
+
it "set proxy host" do
|
12
|
+
proxy_host_name = "test.proxy.com"
|
13
|
+
Rwsc::Config.proxy_host = proxy_host_name
|
14
|
+
should == proxy_host_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Rwsc::Config, "proxy_port" do
|
19
|
+
subject { Rwsc::Config.proxy_port }
|
20
|
+
|
21
|
+
it { should be_nil }
|
22
|
+
|
23
|
+
it "should set proxy port" do
|
24
|
+
proxy_port_val = 33
|
25
|
+
Rwsc::Config.proxy_port = proxy_port_val
|
26
|
+
should == proxy_port_val
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
3
|
+
'..', 'spec_helper'))
|
4
|
+
require 'rwsc'
|
5
|
+
|
6
|
+
describe Rwsc::ItemSearch do
|
7
|
+
it "should raise ArgError with no options msg" do
|
8
|
+
expect {
|
9
|
+
Rwsc::ItemSearch.find(nil)
|
10
|
+
}.should raise_error{ |e|
|
11
|
+
e.should be_instance_of(Rwsc::ArgError)
|
12
|
+
e.to_s.should == "no options"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set developerId" do
|
17
|
+
expect {
|
18
|
+
Rwsc::ItemSearch.find({})
|
19
|
+
}.should raise_error { |e|
|
20
|
+
e.should be_instance_of(Rwsc::ArgError)
|
21
|
+
e.to_s.should == "developerId needed"
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise ArgError on invalid options" do
|
26
|
+
expect {
|
27
|
+
Rwsc::ItemSearch.find({
|
28
|
+
:developerId => 'test_id',
|
29
|
+
:hogehoge => 'aa'
|
30
|
+
})
|
31
|
+
}.should raise_error { |e|
|
32
|
+
e.should be_instance_of(Rwsc::ArgError)
|
33
|
+
e.to_s.should == "hogehoge is invalid option"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
3
|
+
'..', '..', 'spec_helper'))
|
4
|
+
require 'rwsc'
|
5
|
+
|
6
|
+
describe "StringUtils" do
|
7
|
+
it { "itemName".should be_underscore_of("item_name")}
|
8
|
+
it { "itemCode".should be_underscore_of("item_code")}
|
9
|
+
it { "itemPrice".should be_underscore_of("item_price")}
|
10
|
+
it { "itemCaption".should be_underscore_of("item_caption")}
|
11
|
+
it { "itemUrl".should be_underscore_of("item_url")}
|
12
|
+
it { "affiliateUrl".should be_underscore_of("affiliate_url")}
|
13
|
+
it { "imageFlag".should be_underscore_of("image_flag")}
|
14
|
+
it { "smallImageUrl".should be_underscore_of("small_image_url")}
|
15
|
+
it { "mediumImageUrl".should be_underscore_of("medium_image_url")}
|
16
|
+
it { "availability".should be_underscore_of("availability")}
|
17
|
+
it { "taxFlag".should be_underscore_of("tax_flag")}
|
18
|
+
it { "postageFlag".should be_underscore_of("postage_flag")}
|
19
|
+
it { "creditCardFlag".should be_underscore_of("credit_card_flag")}
|
20
|
+
it { "shopOfTheYearFlag".should be_underscore_of("shop_of_the_year_flag")}
|
21
|
+
it { "affiliateRate".should be_underscore_of("affiliate_rate")}
|
22
|
+
it { "startTime".should be_underscore_of("start_time")}
|
23
|
+
it { "endTime".should be_underscore_of("end_time")}
|
24
|
+
it { "reviewCount".should be_underscore_of("review_count")}
|
25
|
+
it { "reviewAverage".should be_underscore_of("review_average")}
|
26
|
+
it { "shopName".should be_underscore_of("shop_name")}
|
27
|
+
it { "shopCode".should be_underscore_of("shop_code")}
|
28
|
+
it { "shopUrl".should be_underscore_of("shop_url")}
|
29
|
+
it { "genreId".should be_underscore_of("genre_id")}
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
4
|
+
'..', 'spec_helper'))
|
5
|
+
require 'rwsc/version'
|
6
|
+
|
7
|
+
describe Rwsc::VERSION do
|
8
|
+
subject { Rwsc::VERSION::STRING }
|
9
|
+
|
10
|
+
it { should == "#{Rwsc::VERSION::MAJOR}." +
|
11
|
+
"#{Rwsc::VERSION::MINOR}." +
|
12
|
+
"#{Rwsc::VERSION::TINY}" }
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rwsc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- byplayer
|
8
|
+
- takayoshi kohayakawa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-24 00:00:00 +09:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: nokogiri
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
version:
|
36
|
+
description: |
|
37
|
+
Rakuten Webservice client library
|
38
|
+
|
39
|
+
email:
|
40
|
+
- byplayer100@gmail.com
|
41
|
+
- takayoshi.kohayakawa@mail.rakuten.co.jp
|
42
|
+
executables: []
|
43
|
+
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.rdoc
|
48
|
+
files:
|
49
|
+
- MIT-LICENSE
|
50
|
+
- Rakefile
|
51
|
+
- README.rdoc
|
52
|
+
- lib/rwsc/web/web_client.rb
|
53
|
+
- lib/rwsc/arg.rb
|
54
|
+
- lib/rwsc/utils/string_utils.rb
|
55
|
+
- lib/rwsc/config.rb
|
56
|
+
- lib/rwsc/operation.rb
|
57
|
+
- lib/rwsc/arg_error.rb
|
58
|
+
- lib/rwsc/result_item.rb
|
59
|
+
- lib/rwsc/item_search.rb
|
60
|
+
- lib/rwsc/version.rb
|
61
|
+
- lib/rwsc/status.rb
|
62
|
+
- lib/rwsc/const.rb
|
63
|
+
- lib/rwsc/status_error.rb
|
64
|
+
- lib/rwsc.rb
|
65
|
+
- spec/rwsc/const_spec.rb
|
66
|
+
- spec/rwsc/utils/string_utils_spec.rb
|
67
|
+
- spec/rwsc/config_spec.rb
|
68
|
+
- spec/rwsc/arg_error_spec.rb
|
69
|
+
- spec/rwsc/item_search_spec.rb
|
70
|
+
- spec/rwsc/version_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
- spec/matchers/utils/be_underscore_of.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://wiki.github.com/byplayer/rwsc
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --line-numbers
|
80
|
+
- --inline-source
|
81
|
+
- --main
|
82
|
+
- README.rdoc
|
83
|
+
- -c UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project: rwsc
|
101
|
+
rubygems_version: 1.3.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Rakuten Webservice client library
|
105
|
+
test_files: []
|
106
|
+
|