iknow 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -22,4 +22,12 @@
22
22
 
23
23
  == 0.2.0
24
24
 
25
- * support almost all API calls
25
+ * support almost all API calls
26
+
27
+ == 0.2.1
28
+
29
+ * maintenance release
30
+
31
+ == 0.2.
32
+
33
+ * add attribution support for add_image & add_sound APIs
@@ -30,8 +30,8 @@ class Iknow::Auth
30
30
  Iknow::Config.oauth_consumer_secret,
31
31
  :http_method => Iknow::Config.oauth_http_method,
32
32
  :scheme => Iknow::Config.oauth_scheme,
33
- :site => Iknow::Config.iknow_api_base_url,
34
- :authorize_url => "#{Iknow::Config.iknow_base_url}/oauth/authorize"
33
+ :site => Iknow::Config.api_base_url,
34
+ :authorize_url => "#{Iknow::Config.base_url}/oauth/authorize"
35
35
  )
36
36
  end
37
37
 
@@ -2,9 +2,9 @@ require 'singleton'
2
2
 
3
3
  class Iknow::Config
4
4
  include Singleton
5
- attr_accessor :protocol, :host, :port, :api_protocol, :api_host, :api_port, :timeout,
6
- :api_key, :oauth_consumer_key, :oauth_consumer_secret, :oauth_http_method, :oauth_scheme,
7
- :user_agent, :application_name, :application_version, :application_url, :source
5
+ attr_accessor :protocol, :host, :port, :api_protocol, :api_host, :api_port, :api_key, :timeout,
6
+ :oauth_consumer_key, :oauth_consumer_secret, :oauth_http_method, :oauth_scheme,
7
+ :user_agent, :application_name, :application_version, :application_url
8
8
 
9
9
  def self.init(&block)
10
10
  conf = Iknow::Config.instance
@@ -14,8 +14,8 @@ class Iknow::Config
14
14
  :api_protocol => 'http',
15
15
  :api_host => 'api.iknow.co.jp',
16
16
  :api_port => 80,
17
- :timeout => 30,
18
17
  :api_key => '',
18
+ :timeout => 30,
19
19
  :oauth_consumer_key => '',
20
20
  :oauth_consumer_secret => '',
21
21
  :oauth_http_method => :post,
@@ -29,12 +29,12 @@ class Iknow::Config
29
29
  conf
30
30
  end
31
31
 
32
- def iknow_base_url
32
+ def base_url
33
33
  port = self.port==80 ? nil : ":#{self.port}"
34
34
  "#{self.protocol}://#{self.host}#{port}"
35
35
  end
36
36
 
37
- def iknow_api_base_url
37
+ def api_base_url
38
38
  port = self.api_port==80 ? nil : ":#{self.api_port}"
39
39
  "#{self.api_protocol}://#{self.api_host}#{port}"
40
40
  end
@@ -1,7 +1,7 @@
1
1
  module Iknow::Version
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- REVISION = 1
4
+ REVISION = 2
5
5
  class << self
6
6
  def to_version
7
7
  "#{MAJOR}.#{MINOR}.#{REVISION}"
@@ -78,20 +78,46 @@ class Iknow::Item < Iknow::Base
78
78
 
79
79
  def add_image(iknow_auth, params)
80
80
  post_params = if params.is_a?(String)
81
- {'image[url]' => params,}
81
+ { 'image[url]' => params }
82
82
  else
83
- {'image[url]' => params[:url],
84
- 'image[list_id]' => params[:list_id] }
83
+ image_params = {
84
+ 'image[url]' => params[:url],
85
+ 'image[list_id]' => params[:list_id]
86
+ }
87
+ if params[:attribution]
88
+ attribution_params = {
89
+ 'attribution[media_entity]' => params[:attribution][:media_entity],
90
+ 'attribution[author]' => params[:attribution][:media_entity],
91
+ 'attribution[author_url]' => params[:attribution][:media_entity],
92
+ 'attribution[attribution_license_id]' => params[:attribution][:media_entity]
93
+ }
94
+ image_params.merge(attribution_params)
95
+ else
96
+ image_params
97
+ end
85
98
  end
86
99
  Iknow::RestClient::Item.add_image(iknow_auth, post_params.merge(:id => self.id))
87
100
  end
88
101
 
89
102
  def add_sound(iknow_auth, params)
90
103
  post_params = if params.is_a?(String)
91
- {'sound[url]' => params,}
104
+ { 'sound[url]' => params }
92
105
  else
93
- {'sound[url]' => params[:url],
94
- 'sound[list_id]' => params[:list_id] }
106
+ sound_params = {
107
+ 'sound[url]' => params[:url],
108
+ 'sound[list_id]' => params[:list_id]
109
+ }
110
+ if params[:attribution]
111
+ attribution_params = {
112
+ 'attribution[media_entity]' => params[:attribution][:media_entity],
113
+ 'attribution[author]' => params[:attribution][:media_entity],
114
+ 'attribution[author_url]' => params[:attribution][:media_entity],
115
+ 'attribution[attribution_license_id]' => params[:attribution][:media_entity]
116
+ }
117
+ sound_params.merge(attribution_params)
118
+ else
119
+ sound_params
120
+ end
95
121
  end
96
122
  Iknow::RestClient::Item.add_sound(iknow_auth, post_params.merge(:id => self.id))
97
123
  end
@@ -99,7 +125,12 @@ class Iknow::Item < Iknow::Base
99
125
  def add_tags(iknow_auth, *tags)
100
126
  post_params = {}
101
127
  tags.each_with_index do |tag, idx|
102
- post_params["semantic_tags[#{idx}][name]"] = tag
128
+ if tag.is_a?(String)
129
+ post_params["semantic_tags[#{idx}][name]"] = tag
130
+ else
131
+ post_params["semantic_tags[#{idx}][name]"] = tag[:name]
132
+ post_params["semantic_tags[#{idx}][disambiguation]"] = tag[:disambiguation]
133
+ end
103
134
  end
104
135
  Iknow::RestClient::Item.add_tags(iknow_auth, post_params.merge(:id => self.id))
105
136
  end
@@ -50,20 +50,46 @@ class Iknow::Sentence < Iknow::Base
50
50
 
51
51
  def add_image(iknow_auth, params)
52
52
  post_params = if params.is_a?(String)
53
- {'image[url]' => params,}
53
+ { 'image[url]' => params }
54
54
  else
55
- {'image[url]' => params[:url],
56
- 'image[list_id]' => params[:list_id] }
55
+ image_params = {
56
+ 'image[url]' => params[:url],
57
+ 'image[list_id]' => params[:list_id]
58
+ }
59
+ if params[:attribution]
60
+ attribution_params = {
61
+ 'attribution[media_entity]' => params[:attribution][:media_entity],
62
+ 'attribution[author]' => params[:attribution][:media_entity],
63
+ 'attribution[author_url]' => params[:attribution][:media_entity],
64
+ 'attribution[attribution_license_id]' => params[:attribution][:media_entity]
65
+ }
66
+ image_params.merge(attribution_params)
67
+ else
68
+ image_params
69
+ end
57
70
  end
58
71
  Iknow::RestClient::Sentence.add_image(iknow_auth, post_params.merge(:id => self.id))
59
72
  end
60
73
 
61
74
  def add_sound(iknow_auth, params)
62
75
  post_params = if params.is_a?(String)
63
- {'sound[url]' => params,}
76
+ { 'sound[url]' => params }
64
77
  else
65
- {'sound[url]' => params[:url],
66
- 'sound[list_id]' => params[:list_id] }
78
+ sound_params = {
79
+ 'sound[url]' => params[:url],
80
+ 'sound[list_id]' => params[:list_id]
81
+ }
82
+ if params[:attribution]
83
+ attribution_params = {
84
+ 'attribution[media_entity]' => params[:attribution][:media_entity],
85
+ 'attribution[author]' => params[:attribution][:media_entity],
86
+ 'attribution[author_url]' => params[:attribution][:media_entity],
87
+ 'attribution[attribution_license_id]' => params[:attribution][:media_entity]
88
+ }
89
+ sound_params.merge(attribution_params)
90
+ else
91
+ sound_params
92
+ end
67
93
  end
68
94
  Iknow::RestClient::Sentence.add_sound(iknow_auth, post_params.merge(:id => self.id))
69
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov