rcicindela 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.
data/History.txt ADDED
@@ -0,0 +1,2 @@
1
+ - 0.1.0
2
+ - Released first version.
data/README.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ = rcicindela
2
+
3
+ http://wiki.github.com/jugyo/rcicindela
4
+
5
+ == DESCRIPTION:
6
+
7
+ RCicindela is a wrapper library for Cicindela.
8
+ Cicindela is a recommendation engine made by Livedoor.
9
+ See Also: http://code.google.com/p/cicindela2/
10
+
11
+ == SYNOPSIS:
12
+
13
+ Initialization:
14
+
15
+ cicindela = RCicindela.new('http://localhost/cicindela')
16
+
17
+ Accumulating data:
18
+
19
+ cicindela.insert_pick(:set => 'test', :user_id => 1, :item_id => 1)
20
+ ...
21
+
22
+ Getting recommendations:
23
+
24
+ cicindela.for_item(:set => 'test', :item_id => 1)
25
+ ...
26
+
27
+ == INSTALL:
28
+
29
+ gem source -a http://gems.github.com
30
+ sudo gem install jugyo-rcicindela
31
+
32
+ == LICENSE:
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2008-2009 jugyo
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift File.dirname(__FILE__) + '/lib/'
3
+ require 'rcicindela'
4
+ require 'spec/rake/spectask'
5
+
6
+ desc 'run all specs'
7
+ Spec::Rake::SpecTask.new do |t|
8
+ t.spec_files = FileList['spec/**/*_spec.rb']
9
+ t.spec_opts = ['-c']
10
+ end
11
+
12
+ desc 'Generate gemspec'
13
+ task :gemspec do |t|
14
+ open('rcicindela.gemspec', "wb" ) do |file|
15
+ file << <<-EOS
16
+ Gem::Specification.new do |s|
17
+ s.name = 'rcicindela'
18
+ s.version = '#{RCicindela::VERSION}'
19
+ s.summary = "RCicindela is a wrapper library for Cicindela."
20
+ s.description = "RCicindela is a wrapper library for Cicindela.\\n" +
21
+ "Cicindela is a recommendation engine made by Livedoor.\\n" +
22
+ "See Also: http://code.google.com/p/cicindela2/"
23
+ s.files = %w( #{Dir['lib/**/*.rb'].join(' ')}
24
+ #{Dir['spec/**/*.rb'].join(' ')}
25
+ README.rdoc
26
+ History.txt
27
+ Rakefile )
28
+ s.author = 'jugyo'
29
+ s.email = 'jugyo.org@gmail.com'
30
+ s.homepage = 'http://github.com/jugyo/rcicindela'
31
+ s.rubyforge_project = 'rcicindela'
32
+ end
33
+ EOS
34
+ end
35
+ puts "Generate gemspec"
36
+ end
37
+
38
+ desc 'Generate gem'
39
+ task :gem => :gemspec do |t|
40
+ system 'gem', 'build', 'rcicindela.gemspec'
41
+ end
data/lib/rcicindela.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'open-uri'
2
+
3
+ class RCicindela
4
+ VERSION = '0.1.0'
5
+
6
+ attr_reader :base_uri
7
+
8
+ def initialize(base_uri)
9
+ @base_uri = base_uri.sub(/\/*$/, '')
10
+ end
11
+
12
+ %w(
13
+ record/insert_pick
14
+ record/insert_rating
15
+ record/insert_tag
16
+ record/set_category
17
+ record/insert_uninterested
18
+ record/delete_pick
19
+ record/delete_rating
20
+ record/delete_tag
21
+ record/delete_uninterested
22
+ record/remove_category
23
+ recommend/for_item
24
+ recommend/for_user
25
+ recommend/similar_users
26
+ ).each do |api_method|
27
+ prefix, method = api_method.split('/')
28
+ define_method(method) do |params|
29
+ get(prefix, {:op => method}.merge(params))
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def get(prefix, params)
36
+ url = base_uri + '/' + prefix + '?' + params.map{ |k, v| [k.to_s, v.to_s] }.sort.map{ |i| i.join('=') }.join('&')
37
+ open(url).read
38
+ end
39
+ end
40
+
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe RCicindela do
6
+ it 'should create instance with base_uri' do
7
+ uri = 'http://localhost/cicindela'
8
+ c = RCicindela.new(uri)
9
+ c.base_uri.should == uri
10
+ end
11
+
12
+ it 'should create instance with base_uri end "/"' do
13
+ uri = 'http://localhost/cicindela/'
14
+ c = RCicindela.new(uri)
15
+ c.base_uri.should == 'http://localhost/cicindela'
16
+ end
17
+
18
+ it 'should create instance with base_uri end "///"' do
19
+ uri = 'http://localhost/cicindela///'
20
+ c = RCicindela.new(uri)
21
+ c.base_uri.should == 'http://localhost/cicindela'
22
+ end
23
+
24
+ describe 'Create instance with "http://localhost/cicindela" as base_uri' do
25
+ before(:each) do
26
+ @cicindela = RCicindela.new('http://localhost/cicindela')
27
+ end
28
+
29
+ it 'call method "get" when call insert_pick' do
30
+ @cicindela.should_receive(:get).with('record', {:op => 'insert_pick', :set => 'test', :user_id => 1, :item_id => 1})
31
+ @cicindela.insert_pick(:set => 'test', :user_id => 1, :item_id => 1)
32
+ end
33
+
34
+ it 'call method "get" when call for_item' do
35
+ @cicindela.should_receive(:get).with('recommend', {:op => 'for_item', :set => 'test', :item_id => 1})
36
+ @cicindela.for_item(:set => 'test', :item_id => 1)
37
+ end
38
+
39
+ it 'call method "open" when call insert_pick' do
40
+ @cicindela.should_receive(:open).
41
+ with("http://localhost/cicindela/record?item_id=1&op=insert_pick&set=test&user_id=1").and_return(StringIO.new('result'))
42
+ result = @cicindela.insert_pick(:set => 'test', :user_id => 1, :item_id => 1)
43
+ result.should == 'result'
44
+ end
45
+
46
+ it 'call method "open" when call for_item' do
47
+ @cicindela.should_receive(:open).
48
+ with("http://localhost/cicindela/recommend?item_id=1&op=for_item&set=test").and_return(StringIO.new('result'))
49
+ result = @cicindela.for_item(:set => 'test', :item_id => 1)
50
+ result.should == 'result'
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+ require 'rcicindela'
3
+
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcicindela
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jugyo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-14 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |-
17
+ RCicindela is a wrapper library for Cicindela.
18
+ Cicindela is a recommendation engine made by Livedoor.
19
+ See Also: http://code.google.com/p/cicindela2/
20
+ email: jugyo.org@gmail.com
21
+ executables: []
22
+
23
+ extensions: []
24
+
25
+ extra_rdoc_files: []
26
+
27
+ files:
28
+ - lib/rcicindela.rb
29
+ - spec/rcicindela_spec.rb
30
+ - spec/spec_helper.rb
31
+ - README.rdoc
32
+ - History.txt
33
+ - Rakefile
34
+ has_rdoc: false
35
+ homepage: http://github.com/jugyo/rcicindela
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project: rcicindela
58
+ rubygems_version: 1.3.2
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: RCicindela is a wrapper library for Cicindela.
62
+ test_files: []
63
+