rightnow-client 0.1.2 → 0.2.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 +7 -0
- data/README.md +13 -3
- data/lib/rightnow/client.rb +6 -5
- data/lib/rightnow/ext/underscore.rb +10 -0
- data/lib/rightnow/version.rb +1 -1
- data/rightnow.gemspec +1 -0
- data/spec/client_spec.rb +24 -10
- data/spec/models/post_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +52 -53
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a503192ee12a709f60ed2c9c35d260aa92a12bc8
|
4
|
+
data.tar.gz: 0d308838e94946b71241c6b30bdfec5c1660b9ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca65d6350e1c34e90016a1b224e3e2d8e915d61567c24cc2b5a84642b325877807ef7aca19baf628f849de2c8c3bd401f3bff6b84494a53027a00046303db1a2
|
7
|
+
data.tar.gz: e6915e566815a54b5ff657850b51ae16ee9a113da0a9f0c6bece3387fa4c4c9f0a1dfb6f8414c7a8cb2870ef29e338ac9817a4bbdcf783556b20e1c7d17579dc
|
data/README.md
CHANGED
@@ -20,13 +20,15 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Instanciate a new client with your community url and API
|
23
|
+
Instanciate a new client with your community url, API keys and API default user:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
client = Rightnow::Client.new "http://community.company.com", :api_key => "YOUR_PUBLIC_KEY", :secret_key => "YOUR_PRIVATE_KEY"
|
26
|
+
client = Rightnow::Client.new "http://community.company.com", :api_key => "YOUR_PUBLIC_KEY", :secret_key => "YOUR_PRIVATE_KEY", :user => "api@dimelo.com"
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
The user specified here is a user of the community (usually a superadmin) which must have the permissions for all the actions you want to do with the client.
|
30
|
+
|
31
|
+
Then you can query the search API with:
|
30
32
|
|
31
33
|
```ruby
|
32
34
|
res = client.search term: 'white', limit: 50
|
@@ -79,6 +81,14 @@ Or any other generic request:
|
|
79
81
|
client.request 'UserList', :as => 'admin@domain.com'
|
80
82
|
```
|
81
83
|
|
84
|
+
## Debug
|
85
|
+
|
86
|
+
Instanciate the client with a `:debug => true` option to get debug info:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
client = Rightnow::Client.new "http://community.company.com", ..., :debug => true
|
90
|
+
```
|
91
|
+
|
82
92
|
## Contributing
|
83
93
|
|
84
94
|
1. Fork it
|
data/lib/rightnow/client.rb
CHANGED
@@ -8,16 +8,18 @@ require 'rexml/document'
|
|
8
8
|
|
9
9
|
module Rightnow
|
10
10
|
class Client
|
11
|
-
attr_accessor :host, :api_key, :secret_key, :version
|
11
|
+
attr_accessor :host, :api_key, :secret_key, :version, :user, :debug
|
12
12
|
|
13
13
|
def initialize host, opts = {}
|
14
14
|
@host = host
|
15
15
|
@api_key = opts[:api_key]
|
16
16
|
@secret_key = opts[:secret_key]
|
17
|
+
@user = opts[:user] || 'hl.api@hivelive.com'
|
17
18
|
@version = opts[:version] || '2010-05-15'
|
19
|
+
@debug = opts[:debug]
|
18
20
|
|
19
21
|
@conn = Faraday.new(:url => host) do |faraday|
|
20
|
-
|
22
|
+
faraday.response :logger if @debug
|
21
23
|
faraday.adapter :typhoeus
|
22
24
|
end
|
23
25
|
end
|
@@ -185,10 +187,9 @@ module Rightnow
|
|
185
187
|
end
|
186
188
|
|
187
189
|
def request action, opts = {}
|
188
|
-
debug = opts.delete(:debug)
|
189
190
|
verb = opts.delete(:verb) || :get
|
190
191
|
response = @conn.send(verb, 'api/endpoint', signed_params(action, opts))
|
191
|
-
puts response.body if debug
|
192
|
+
puts response.body if @debug
|
192
193
|
parse response
|
193
194
|
end
|
194
195
|
|
@@ -220,7 +221,7 @@ module Rightnow
|
|
220
221
|
params = {
|
221
222
|
'Action' => action,
|
222
223
|
'ApiKey' => api_key,
|
223
|
-
'PermissionedAs' => opts.delete(:as) ||
|
224
|
+
'PermissionedAs' => opts.delete(:as) || @user,
|
224
225
|
'SignatureVersion' => '2',
|
225
226
|
'version' => version
|
226
227
|
}
|
@@ -13,4 +13,14 @@ class Hash
|
|
13
13
|
def underscore
|
14
14
|
convert_hash_keys(self)
|
15
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# backport
|
19
|
+
require 'active_support'
|
20
|
+
class String
|
21
|
+
# http://apidock.com/rails/String/underscore
|
22
|
+
# File activesupport/lib/active_support/core_ext/string/inflections.rb, line 118
|
23
|
+
def underscore
|
24
|
+
ActiveSupport::Inflector.underscore(self)
|
25
|
+
end
|
16
26
|
end
|
data/lib/rightnow/version.rb
CHANGED
data/rightnow.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency 'rspec', '~> 2.6'
|
19
19
|
gem.add_development_dependency 'webmock', '~> 1.8'
|
20
20
|
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'activesupport'
|
21
22
|
gem.files = `git ls-files`.split($/)
|
22
23
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
23
24
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
data/spec/client_spec.rb
CHANGED
@@ -10,13 +10,15 @@ describe Rightnow::Client do
|
|
10
10
|
client.api_key.should == nil
|
11
11
|
client.secret_key.should == nil
|
12
12
|
client.version.should == '2010-05-15'
|
13
|
+
client.user.should == 'hl.api@hivelive.com'
|
13
14
|
end
|
14
15
|
|
15
16
|
it "accepts options" do
|
16
|
-
client = Rightnow::Client.new "host", :api_key => "APIKEY", :secret_key => "SECRETKEY", :version => '2042-13-13'
|
17
|
+
client = Rightnow::Client.new "host", :api_key => "APIKEY", :secret_key => "SECRETKEY", :version => '2042-13-13', :user => 'api@domain.com'
|
17
18
|
client.api_key.should == "APIKEY"
|
18
19
|
client.secret_key.should == "SECRETKEY"
|
19
20
|
client.version.should == '2042-13-13'
|
21
|
+
client.user.should == 'api@domain.com'
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -26,10 +28,15 @@ describe Rightnow::Client do
|
|
26
28
|
client.search(:term => 'white', :sort => 'az', :page => 2).should == []
|
27
29
|
end
|
28
30
|
|
31
|
+
it "accepts `as` option" do
|
32
|
+
stub_request(:get, "http://something/api/endpoint?Action=Search&ApiKey=API&PermissionedAs=api@domain.com&Signature=MmHBXKKsEfJJPX8EW%2B8ZqMnGEGc=&SignatureVersion=2&format=json&limit=20&objects=Posts&sort=az&start=21&term=white&version=2010-05-15").to_return :body => '[]'
|
33
|
+
client.search(:term => 'white', :sort => 'az', :page => 2, :as => 'api@domain.com').should == []
|
34
|
+
end
|
35
|
+
|
29
36
|
it "returns correctly parsed response" do
|
30
37
|
stub_request(:get, /.*/).to_return :body => fixture('search.json')
|
31
38
|
response = client.search
|
32
|
-
response.should
|
39
|
+
response.size.should == 5
|
33
40
|
response.first.should be_instance_of(Rightnow::Models::Post)
|
34
41
|
end
|
35
42
|
end
|
@@ -52,7 +59,7 @@ describe Rightnow::Client do
|
|
52
59
|
|
53
60
|
it "accepts multiple elements" do
|
54
61
|
posts = client.post_get ["fa8e6cc713", "fa8e6cb714"]
|
55
|
-
posts.should
|
62
|
+
posts.size.should == 2
|
56
63
|
posts.first.should be_instance_of(Rightnow::Models::Post)
|
57
64
|
end
|
58
65
|
|
@@ -92,7 +99,7 @@ describe Rightnow::Client do
|
|
92
99
|
|
93
100
|
it "returns correctly parsed response" do
|
94
101
|
response = client.comment_list "fa8e6cc713"
|
95
|
-
response.should
|
102
|
+
response.size.should == 3
|
96
103
|
response.first.should be_instance_of(Rightnow::Models::Comment)
|
97
104
|
end
|
98
105
|
end
|
@@ -100,10 +107,8 @@ describe Rightnow::Client do
|
|
100
107
|
|
101
108
|
describe '#comment_add' do
|
102
109
|
it "compute correct request" do
|
103
|
-
|
104
|
-
|
105
|
-
client.comment_add("fa8e6cc713", 'test', as: 'toto')
|
106
|
-
end
|
110
|
+
stub_request(:post, "http://something/api/endpoint").with(:body => {"Action"=>"CommentAdd", "ApiKey"=>"API", "PermissionedAs"=>"toto", "Signature"=>"kJXXoPZ7xexKxv8duTYmtS519GY=", "SignatureVersion"=>"2", "format"=>"json", "payload"=>"<?xml version='1.0'?><comments><comment><value><![CDATA[test]]></value></comment></comments>", "postHash"=>"fa8e6cc713", "version"=>"2010-05-15"}).to_return :body => '{"comment": {}}'
|
111
|
+
client.comment_add("fa8e6cc713", 'test', as: 'toto')
|
107
112
|
end
|
108
113
|
|
109
114
|
it "return comment model" do
|
@@ -158,7 +163,7 @@ describe Rightnow::Client do
|
|
158
163
|
stub_request(:get, /.*/).
|
159
164
|
to_return(:status => 200, :body => fixture('search.json'))
|
160
165
|
results = client.request 'Search'
|
161
|
-
results.should
|
166
|
+
results.size.should == 5
|
162
167
|
results.first.should == fixture('post.rb', :ruby)
|
163
168
|
end
|
164
169
|
end
|
@@ -177,7 +182,7 @@ describe Rightnow::Client do
|
|
177
182
|
it { should include('PermissionedAs' => 'hl.api@hivelive.com') }
|
178
183
|
it { should include('Signature' => 'vIONtWGXvdAG/McOTM0KuFD+O2g=') }
|
179
184
|
it { should include('format' => 'json') }
|
180
|
-
|
185
|
+
it { subject.size.should == 7 }
|
181
186
|
|
182
187
|
context "with custom permission" do
|
183
188
|
subject { client.send :signed_params, "Something", :as => 'email@domain.com' }
|
@@ -193,5 +198,14 @@ describe Rightnow::Client do
|
|
193
198
|
it { should include('Signature' => 'vIONtWGXvdAG/McOTM0KuFD+O2g=') }
|
194
199
|
it { should include('term' => 'white') }
|
195
200
|
end
|
201
|
+
|
202
|
+
context "with custom user in client" do
|
203
|
+
before { client.user = 'api@domain.com' }
|
204
|
+
|
205
|
+
it { should include('PermissionedAs' => 'api@domain.com') }
|
206
|
+
it { should include('Signature' => 'tdUCB7FafhflaQ/pCIWK+NQnhMY=') }
|
207
|
+
it { should_not include('as') }
|
208
|
+
end
|
209
|
+
|
196
210
|
end
|
197
211
|
end
|
data/spec/models/post_spec.rb
CHANGED
@@ -59,7 +59,7 @@ describe Rightnow::Models::Post do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "stores fields details" do
|
62
|
-
post.fields.should
|
62
|
+
post.fields.size.should == 2
|
63
63
|
# Title
|
64
64
|
post.fields.first.should be_instance_of(Rightnow::Models::Field)
|
65
65
|
post.fields.first.id.should == 40695
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,112 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightnow-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.2
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Adrien Jarthon
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.8.0
|
20
|
-
none: false
|
21
|
-
name: faraday
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
23
|
requirements:
|
26
|
-
- -
|
24
|
+
- - ">="
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
version: 0.8.0
|
29
|
-
none: false
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
32
30
|
requirements:
|
33
|
-
- -
|
31
|
+
- - ">="
|
34
32
|
- !ruby/object:Gem::Version
|
35
33
|
version: 1.0.0
|
36
|
-
none: false
|
37
|
-
name: virtus
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
37
|
requirements:
|
42
|
-
- -
|
38
|
+
- - ">="
|
43
39
|
- !ruby/object:Gem::Version
|
44
40
|
version: 1.0.0
|
45
|
-
none: false
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
|
42
|
+
name: typhoeus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
48
44
|
requirements:
|
49
|
-
- -
|
45
|
+
- - ">="
|
50
46
|
- !ruby/object:Gem::Version
|
51
47
|
version: 0.5.0
|
52
|
-
none: false
|
53
|
-
name: typhoeus
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
|
-
- -
|
52
|
+
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: 0.5.0
|
61
|
-
none: false
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
|
-
- - ~>
|
59
|
+
- - "~>"
|
66
60
|
- !ruby/object:Gem::Version
|
67
61
|
version: '2.6'
|
68
|
-
none: false
|
69
|
-
name: rspec
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
65
|
requirements:
|
74
|
-
- - ~>
|
66
|
+
- - "~>"
|
75
67
|
- !ruby/object:Gem::Version
|
76
68
|
version: '2.6'
|
77
|
-
none: false
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
|
-
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
80
72
|
requirements:
|
81
|
-
- - ~>
|
73
|
+
- - "~>"
|
82
74
|
- !ruby/object:Gem::Version
|
83
75
|
version: '1.8'
|
84
|
-
none: false
|
85
|
-
name: webmock
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
|
-
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
79
|
requirements:
|
90
|
-
- - ~>
|
80
|
+
- - "~>"
|
91
81
|
- !ruby/object:Gem::Version
|
92
82
|
version: '1.8'
|
93
|
-
none: false
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
|
-
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
96
86
|
requirements:
|
97
|
-
- -
|
87
|
+
- - ">="
|
98
88
|
- !ruby/object:Gem::Version
|
99
89
|
version: '0'
|
100
|
-
none: false
|
101
|
-
name: rake
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
104
99
|
requirement: !ruby/object:Gem::Requirement
|
105
100
|
requirements:
|
106
|
-
- -
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
107
109
|
- !ruby/object:Gem::Version
|
108
110
|
version: '0'
|
109
|
-
none: false
|
110
111
|
description: Rightnow API Ruby wrapper
|
111
112
|
email:
|
112
113
|
- adrien.jarthon@dimelo.com
|
@@ -114,8 +115,8 @@ executables: []
|
|
114
115
|
extensions: []
|
115
116
|
extra_rdoc_files: []
|
116
117
|
files:
|
117
|
-
- .gitignore
|
118
|
-
- .travis.yml
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
119
120
|
- Gemfile
|
120
121
|
- LICENSE.txt
|
121
122
|
- README.md
|
@@ -147,27 +148,26 @@ files:
|
|
147
148
|
- spec/spec_helper.rb
|
148
149
|
homepage: https://github.com/dimelo/rightnow
|
149
150
|
licenses: []
|
151
|
+
metadata: {}
|
150
152
|
post_install_message:
|
151
153
|
rdoc_options: []
|
152
154
|
require_paths:
|
153
155
|
- lib
|
154
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
155
157
|
requirements:
|
156
|
-
- -
|
158
|
+
- - ">="
|
157
159
|
- !ruby/object:Gem::Version
|
158
160
|
version: '0'
|
159
|
-
none: false
|
160
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
162
|
requirements:
|
162
|
-
- -
|
163
|
+
- - ">="
|
163
164
|
- !ruby/object:Gem::Version
|
164
165
|
version: '0'
|
165
|
-
none: false
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version:
|
168
|
+
rubygems_version: 2.2.2
|
169
169
|
signing_key:
|
170
|
-
specification_version:
|
170
|
+
specification_version: 4
|
171
171
|
summary: Ruby wrapper for the Oracle Rightnow Social API v2
|
172
172
|
test_files:
|
173
173
|
- spec/client_spec.rb
|
@@ -182,4 +182,3 @@ test_files:
|
|
182
182
|
- spec/models/post_spec.rb
|
183
183
|
- spec/models/user_spec.rb
|
184
184
|
- spec/spec_helper.rb
|
185
|
-
has_rdoc:
|