rzotero 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ pkg
2
+ .DS_Store
3
+ log
4
+ doc
5
+ rZotero-*.gem
6
+ rdoc
7
+ *.gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2010 Wayne Graham
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,39 @@
1
+ = rzotero
2
+
3
+ A simple, extensible Ruby client for the Zotero API.
4
+
5
+ == Installation
6
+ gem install rzotero
7
+
8
+ == Dependencies
9
+ rzotero uses the Nokogiri gem to parse the RSS feed from Zotero
10
+
11
+ == Usage
12
+
13
+ The Zotero API currently requires your user ID (not your user name) to properly construct the API call. If you need to look up your user id, head over to {Zotero ID Finder}[http://zotero-id-finder.heroku.com/]
14
+
15
+ require 'rubygems'
16
+ require 'rzotero'
17
+
18
+ zotero = RZotero.new(1, 'api_key')
19
+
20
+ puts zotero.user
21
+ puts zotero.key
22
+ puts zotero.items
23
+ puts zotero.item(2)
24
+ puts zotero.collections
25
+ puts zotero.collection(1)
26
+
27
+ == Note on Patches/Pull Requests
28
+
29
+ * Fork the project.
30
+ * Make your feature addition or bug fix.
31
+ * Add tests for it. This is important so I don't break it in a
32
+ future version unintentionally.
33
+ * Commit, do not mess with rakefile, version, or history.
34
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
35
+ * Send me a pull request. Bonus points for topic branches.
36
+
37
+ == Copyright
38
+
39
+ Copyright (c) 2010 Wayne Graham. See link:LICENSE for details.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rzotero"
8
+ gem.summary = %Q{A Ruby client for the Zotero API}
9
+ gem.description = %Q{rZotero provides a simple and extensible library for working with the Zotero API}
10
+ gem.email = "wayne.graham@gmail.com"
11
+ gem.homepage = "http://github.com/waynegraham/rzotero"
12
+ gem.authors = ["Wayne Graham"]
13
+
14
+ # gem dependencies
15
+ gem.add_dependency "nokogiri", ">= 1.4.0"
16
+
17
+ # dev dependencies
18
+ gem.add_development_dependency "rspec", ">= 1.2.9"
19
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
20
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
+ end
22
+ Jeweler::GemcutterTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
+ end
26
+
27
+ require 'spec/rake/spectask'
28
+ Spec::Rake::SpecTask.new(:spec) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.spec_files = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ spec.libs << 'lib' << 'spec'
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "rzotero #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rzotero'
3
+ # require 'open-uri'
4
+ # require 'nokogiri'
5
+
6
+
7
+ zotero = RZotero.new(43, 'SqbbheQDVlJQUgd9NQVgnUjT')
8
+
9
+ puts zotero.user
10
+ puts zotero.key
11
+
12
+ puts zotero.items
13
+ puts zotero.item(11944)
14
+ puts zotero.collections
15
+ puts zotero.collection(276)
16
+
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ class RZotero
6
+
7
+ BASE_URL = 'https://api.zotero.org'
8
+
9
+ attr_accessor :rzotero_error
10
+
11
+ def initialize(user_id, api_key)
12
+ @rzotero_error = false
13
+ begin
14
+ #TODO need to check if the user_id is numeric;
15
+ raise TypeError, "user_id must be an Integer" unless user_id.kind_of? Integer
16
+ raise TypeError, "api_key must be a String" unless api_key.kind_of? String
17
+
18
+ @user_id = user_id
19
+ @api_key = api_key
20
+ rescue TypeError
21
+ @rzotero_error = true
22
+ end
23
+ end
24
+
25
+ def key
26
+ return @api_key
27
+ end
28
+
29
+ # def key!(api_key)
30
+ # raise TypeError, "api_key must be a String" unless user_id.kind_of? String
31
+ # @api_key = api_key
32
+ # end
33
+
34
+ def user
35
+ return @user_id
36
+ end
37
+
38
+ # def user!(user_id)
39
+ # raise TypeError, "user_id must be an Integer" unless user_id.kind_of? Integer
40
+ # @user_id = user_id
41
+ # end
42
+
43
+ def base
44
+ return BASE_URL
45
+ end
46
+
47
+ # Returns all items for the user
48
+ def items
49
+ url = "#{BASE_URL}/users/#{@user_id}/items?key=#{@api_key}"
50
+ return Nokogiri.parse(open(url))
51
+ end
52
+
53
+ # Returns a specific item
54
+ def item(id)
55
+ url = "#{BASE_URL}/users/#{@user_id}/items/#{id}?key=#{@api_key}"
56
+ return Nokogiri.parse(open(url))
57
+ end
58
+
59
+ def item_children(id)
60
+ url = "#{BASE_URL}/users/#{@user_id}/items/#{id}/children?key=#{@api_key}"
61
+ return Nokogiri.parse(open(url))
62
+ end
63
+
64
+ def collections
65
+ url = "#{BASE_URL}/users/#{@user_id}/collections?key=#{@api_key}"
66
+ return Nokogiri.parse(open(url))
67
+ end
68
+
69
+ def collection(id)
70
+ url = "#{BASE_URL}/users/#{@user_id}/collections/#{id}?key=#{@api_key}"
71
+ return Nokogiri.parse(open(url))
72
+ end
73
+
74
+ # def user_id
75
+ # url = "#{OLD_BASE_URL}/users/#{USER}"
76
+ # doc = Nokogiri.parse(open(url)).xpath("//id")
77
+ # return doc.to_s[/[0-9]+/]
78
+ # end
79
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "RZotero" do
4
+
5
+ before(:each) do
6
+ @user_id = 43
7
+ @api_key = 'test'
8
+ @zotero = RZotero.new(@user_id, @api_key)
9
+ end
10
+
11
+ it "should not be valid with a String user_id" do
12
+ @zotero = RZotero.new("43", "test")
13
+ @zotero.rzotero_error.should be_true
14
+ @zotero.should raise_error
15
+ end
16
+
17
+ it "should not be valid with an Integer api_key" do
18
+ @zotero = RZotero.new("test", 43)
19
+ @zotero.rzotero_error.should be_true
20
+ @zotero.should raise_error
21
+ end
22
+
23
+ it "should get the correct key ('test')" do
24
+ @zotero.key.should eql(@api_key)
25
+ end
26
+
27
+ it "should get the correct user_id ('43')" do
28
+ @zotero.user.should eql(@user_id)
29
+ end
30
+
31
+ it "shuold get the correct BASE_URL" do
32
+ @zotero.base.should eql('https://api.zotero.org')
33
+ end
34
+
35
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rzotero'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rzotero
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Wayne Graham
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-14 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 0
31
+ version: 1.4.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 9
45
+ version: 1.2.9
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: fakeweb
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ - 8
59
+ version: 1.2.8
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: rZotero provides a simple and extensible library for working with the Zotero API
63
+ email: wayne.graham@gmail.com
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - LICENSE
70
+ - README.rdoc
71
+ files:
72
+ - .gitignore
73
+ - LICENSE
74
+ - README.rdoc
75
+ - Rakefile
76
+ - VERSION
77
+ - lib/rzotero.rb
78
+ - spec/rzotero_spec.rb
79
+ - spec/spec.opts
80
+ - spec/spec_helper.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/waynegraham/rzotero
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --charset=UTF-8
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.3.6
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A Ruby client for the Zotero API
111
+ test_files:
112
+ - spec/rzotero_spec.rb
113
+ - spec/spec_helper.rb
114
+ - examples/test.rb