dmm-sdk-ruby 0.0.2 → 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 +4 -4
- data/lib/dmm/core.rb +144 -59
- data/lib/dmm/version.rb +1 -1
- metadata +2 -4
- data/lib/dmm/api/base.rb +0 -7
- data/lib/dmm/core/configuration.rb +0 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c630d8b65404eedf251414cbdeadeabc7b7d24
|
4
|
+
data.tar.gz: a0b9670356a2c969f8281c4ad58572ac5bf610bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2283571572194587ebaa0d81acecc6ce1be08f6a6a0e2c5aa0e8f57167f97f306e72b7af072210db5841c1413e6ba33c7c955d0d6b69a7169e2a985766df4a7
|
7
|
+
data.tar.gz: 3bcf864a109b3a007ca739337bfa9d323f5d798444b325212ace3c3440c1bbbc0ec84fa9b790c37bd0869b9792b525b565edcdddfeb543e597c69d5501049a5e
|
data/lib/dmm/core.rb
CHANGED
@@ -1,77 +1,162 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
#-*- encoding: utf-8 -*-
|
2
|
+
require 'open-uri'
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'dmm/version'
|
3
5
|
|
4
|
-
module
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
6
|
+
module Dmm
|
7
|
+
module Configuration
|
8
|
+
def initialize(api_id, affiliate_id)
|
9
|
+
@url = 'http://affiliate-api.dmm.com/'
|
10
|
+
@api = api_id
|
11
|
+
@id = affiliate_id
|
12
|
+
@site = 'DMM.co.jp'
|
13
|
+
@version = '2.00'
|
14
|
+
puts 'initialize ok!!'
|
12
15
|
end
|
13
|
-
attr_render :class_name, :full_name, :method_name, :method_alias, :old_name
|
14
16
|
end
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#module Http
|
34
|
-
#end
|
35
|
-
end
|
19
|
+
module Dmm
|
20
|
+
class Com
|
21
|
+
include Dmm::Configuration
|
22
|
+
|
23
|
+
#### Search
|
24
|
+
# 検索
|
25
|
+
# @param [String] word 検索キーワード
|
26
|
+
# @return [Hash] APIのレスポンスをXML形式からHash形式に変更したもの
|
27
|
+
def keyword(word, options = {:service => nil, :floor => nil, :hits => 20, :offset => 1, :sort => 'rank'})
|
28
|
+
uri = create_uri(word)
|
29
|
+
xmlbody = get_api(uri)
|
30
|
+
@xmldoc = REXML::Document.new(xmlbody)
|
31
|
+
@hashdoc = from_xml(@xmldoc)
|
32
|
+
@hashdoc
|
33
|
+
end
|
34
|
+
|
36
35
|
|
37
|
-
|
36
|
+
#### Hash Analyze
|
37
|
+
# @param [Hash] h DMMAPIのHash化したもの。
|
38
|
+
# nil ok
|
39
|
+
# @return [Hash] requestの下を返す
|
40
|
+
def get_request(h = nil)
|
41
|
+
h ||= @hashdoc
|
42
|
+
h[:response][:request]
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [Hash] h DMMAPIのHash化したもの。
|
46
|
+
# nil ok
|
47
|
+
# @return [Hash] requestの下を返す
|
48
|
+
def get_result(h = nil)
|
49
|
+
h ||= @hashdoc
|
50
|
+
h[:response][:result]
|
51
|
+
end
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
|
53
|
+
# @param [Hash] h DMMAPIのHash化したもの。
|
54
|
+
# nil ok
|
55
|
+
# @return [Hash] requestの下を返す
|
56
|
+
def get_items(h = nil)
|
57
|
+
h ||= @hashdoc
|
58
|
+
h[:response][:result][:items][:item]
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [Hash] h DMMAPIのHash化したもの。
|
62
|
+
# nil ok
|
63
|
+
# @return [Array] titleを返す
|
64
|
+
def get_titles(h = nil)
|
65
|
+
h ||= @hashdoc
|
66
|
+
items = get_items(h)
|
67
|
+
arr = []
|
68
|
+
items.each do |i|
|
69
|
+
arr << i[:title]
|
42
70
|
end
|
43
|
-
|
71
|
+
arr
|
72
|
+
end
|
73
|
+
|
74
|
+
# @param [Hash] h DMMAPIのHash化したもの。
|
75
|
+
# nil ok
|
76
|
+
# @return [Array] 複数のimageとそのTitleを返す
|
77
|
+
# arr [ {:title => "", :images => ["url"]},...]
|
78
|
+
def get_title_images(h = nil)
|
79
|
+
h ||= @hashdoc
|
80
|
+
arr = []
|
81
|
+
items = get_items(h)
|
82
|
+
titles = get_titles(h)
|
83
|
+
items.each_with_index do |m, i|
|
84
|
+
arr << { :title => titles[i], :list => m[:imageURL][:list], :small => m[:imageURL][:small], :large => m[:imageURL][:large] }
|
85
|
+
end
|
86
|
+
arr
|
44
87
|
end
|
45
88
|
|
46
|
-
|
89
|
+
# @param [Hash] h DMMAPIのHash化したもの。
|
90
|
+
# nil ok
|
91
|
+
# @return [Array] 複数のimageとそのTitleを返す
|
92
|
+
# arr [ {:title => "", :images => ["url"]},...]
|
93
|
+
def get_sample_images(h = nil)
|
94
|
+
h ||= @hashdoc
|
95
|
+
arr = []
|
96
|
+
items = get_items
|
97
|
+
titles = get_titles(h)
|
98
|
+
items.each_with_index do |m, i|
|
99
|
+
arr << { :title => titles[i], :images => m[:sampleImageURL][:sample_s][:image]}
|
100
|
+
end
|
101
|
+
arr
|
102
|
+
end
|
47
103
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
104
|
+
#util
|
105
|
+
def create_uri(word, options = {})
|
106
|
+
arr = []
|
107
|
+
arr << "api_id=#{@api}"
|
108
|
+
arr << "affiliate_id=#{@id}-991"
|
109
|
+
arr << "operation=ItemList"
|
110
|
+
arr << "version=#{@version}"
|
111
|
+
arr << "timestamp=#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
112
|
+
arr << "site=#{@site}"
|
113
|
+
arr << "keyword=#{word}"
|
114
|
+
encode_uri = ("#{@url}?#{arr.join('&')}").encode("EUC-JP","UTF-8")
|
115
|
+
URI.escape(encode_uri)
|
52
116
|
end
|
53
117
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
118
|
+
def get_api(uri)
|
119
|
+
xml = ""
|
120
|
+
open(uri) do |o|
|
121
|
+
o.each do |l|
|
122
|
+
if /\<parameter\sname/ =~ l
|
123
|
+
# なんでParameterの中に入れるんだろうね(´・ω・`)
|
124
|
+
# 取り出そうよ
|
125
|
+
b = l.scan(/\"(.*?)\"/).flatten
|
126
|
+
xml << "<#{b[0]}>"
|
127
|
+
xml << "#{b[1]}"
|
128
|
+
xml << "</#{b[0]}>"
|
129
|
+
else
|
130
|
+
xml << l
|
65
131
|
end
|
66
132
|
end
|
133
|
+
|
67
134
|
end
|
68
|
-
|
69
|
-
|
135
|
+
xml
|
136
|
+
end
|
137
|
+
|
138
|
+
#rexml
|
139
|
+
def from_xml(rexml)
|
140
|
+
xml_elem_to_hash rexml.root
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
def xml_elem_to_hash(elem)
|
145
|
+
value = if elem.has_elements?
|
146
|
+
children = {}
|
147
|
+
elem.each_element do |e|
|
148
|
+
children.merge!(xml_elem_to_hash(e)) do |k,v1,v2|
|
149
|
+
v1.class == Array ? v1 << v2 : [v1,v2]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
children
|
153
|
+
else
|
154
|
+
elem.text
|
155
|
+
end
|
156
|
+
{ elem.name.to_sym => value }
|
157
|
+
end
|
70
158
|
|
71
|
-
SERVICES.values.each do |svc|
|
72
|
-
autoload(svc.class_name, "aws/"#{svc.old_name}")
|
73
|
-
require "aws/#{svc.old_name}/config"
|
74
159
|
end
|
75
|
-
|
76
160
|
end
|
77
|
-
|
161
|
+
# d = Dmm::Com.new
|
162
|
+
# d.keyword 'aa'
|
data/lib/dmm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dmm-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sutoh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,9 +53,7 @@ files:
|
|
53
53
|
- dmm-sdk-ruby.gemspec
|
54
54
|
- lib/dmm-sdk.rb
|
55
55
|
- lib/dmm.rb
|
56
|
-
- lib/dmm/api/base.rb
|
57
56
|
- lib/dmm/core.rb
|
58
|
-
- lib/dmm/core/configuration.rb
|
59
57
|
- lib/dmm/version.rb
|
60
58
|
homepage: ''
|
61
59
|
licenses:
|
data/lib/dmm/api/base.rb
DELETED
@@ -1,156 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module AWS
|
5
|
-
module Core
|
6
|
-
class Confiduration
|
7
|
-
|
8
|
-
# Creates a new Configuration object.
|
9
|
-
# @param options (see DMM.config)
|
10
|
-
# @option options (see DMM.config)
|
11
|
-
def initialize options = {}
|
12
|
-
@created = options.delete(:__created__) || {}
|
13
|
-
|
14
|
-
options.each_pair do |opt_name, value|
|
15
|
-
opt_name = opt_name.to_sym
|
16
|
-
if self.class.accepted_options.include?(opt_name)
|
17
|
-
supplied[opt_name] = value
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Hash] Returns a hash with your configured credentials.
|
23
|
-
def credentials
|
24
|
-
credentials = {}
|
25
|
-
[:api_id, :affiliate_id].each do |opt|
|
26
|
-
if value = credential_provider.send(opt)
|
27
|
-
credentials[opt] = value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
credentials
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
def with options = {}
|
35
|
-
# symbolize option keys
|
36
|
-
options = options.inject({}) {|h,kv| h[kv.first.to_sym] = kv.last; h }
|
37
|
-
values = supplied.merge(options)
|
38
|
-
if supplied == values
|
39
|
-
self # nothing changed
|
40
|
-
else
|
41
|
-
self.class.new(values.merge(:__created__ => @created.dup))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
# @return [Hash] Returns a hash of all configuration values.
|
47
|
-
def to_h
|
48
|
-
self.class.accepted_options.inject({}) do |h,k|
|
49
|
-
h.merge(k => send(k))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
alias_method :to_hash, :to_h
|
53
|
-
|
54
|
-
|
55
|
-
# @return [Boolean] Returns true if the two configuration objects have
|
56
|
-
# the same values.
|
57
|
-
def eql? other
|
58
|
-
other.is_a?(self.class) and self.supplied == other.supplied
|
59
|
-
end
|
60
|
-
alias_method :==, :eql?
|
61
|
-
|
62
|
-
|
63
|
-
def inspect
|
64
|
-
"<#{self.class.name}>"
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
add_options :api_id
|
71
|
-
|
72
|
-
add_options :affiliate_id
|
73
|
-
|
74
|
-
def supplied
|
75
|
-
@supplied ||= {}
|
76
|
-
end
|
77
|
-
|
78
|
-
=begin
|
79
|
-
class << self
|
80
|
-
def accepted_options
|
81
|
-
@options ||= Set.new
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
def add_option name, default_value = nil, options = {}, &transform
|
86
|
-
accepted_options << name
|
87
|
-
define_method(name) do |&default_override|
|
88
|
-
value =
|
89
|
-
if supplied.has_key?(name)
|
90
|
-
supplied[name]
|
91
|
-
elsif default_override
|
92
|
-
default_override.call
|
93
|
-
else
|
94
|
-
default_value
|
95
|
-
end
|
96
|
-
transform ? transform.call(self, value) : value
|
97
|
-
end
|
98
|
-
alias_method("#{name}?", name) if options[:boolean]
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
# Configuration options that have dependencies are re-recreated
|
103
|
-
# anytime one of their dependent configuration values are
|
104
|
-
# changed.
|
105
|
-
# @api private
|
106
|
-
def add_option_with_needs name, needs, &create_block
|
107
|
-
accepted_options << name
|
108
|
-
define_method(name) do
|
109
|
-
return supplied[name] if supplied.has_key?(name)
|
110
|
-
needed = needs.inject({}) {|h,need| h.merge(need => send(need)) }
|
111
|
-
unless @created.key?(name) and @created[name][:needed] == needed
|
112
|
-
created = {}
|
113
|
-
created[:object] = create_block.call(self,needed)
|
114
|
-
created[:needed] = needed
|
115
|
-
@created[name] = created
|
116
|
-
end
|
117
|
-
@created[name][:object]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def add_service name, ruby_name, endpoint_pattern = nil, &endpoint_builder
|
122
|
-
svc = SERVICES[name]
|
123
|
-
svc_opt = svc.method_name
|
124
|
-
ruby_name = svc.old_name
|
125
|
-
add_option(svc_opt, {})
|
126
|
-
needs = [
|
127
|
-
:"#{ruby_name}_endpoint",
|
128
|
-
:"#{ruby_name}_port",
|
129
|
-
:"#{ruby_name}_region",
|
130
|
-
:credential_provider,
|
131
|
-
:http_handler,
|
132
|
-
:http_read_timeout,
|
133
|
-
:http_continue_timeout,
|
134
|
-
:http_continue_threshold,
|
135
|
-
:log_formatter,
|
136
|
-
:log_level,
|
137
|
-
:logger,
|
138
|
-
:proxy_uri,
|
139
|
-
:max_retries,
|
140
|
-
:stub_requests?,
|
141
|
-
:ssl_verify_peer?,
|
142
|
-
:ssl_ca_file,
|
143
|
-
:ssl_ca_path,
|
144
|
-
:use_ssl?,
|
145
|
-
:user_agent_prefix,
|
146
|
-
]
|
147
|
-
create_block = lambda do |config,client_options|
|
148
|
-
AWS.const_get(name)::Client.new(:config => config)
|
149
|
-
end
|
150
|
-
add_option_with_needs :"#{ruby_name}_client", needs, &create_block
|
151
|
-
end
|
152
|
-
end
|
153
|
-
=end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|