Class: RZotero
- Inherits:
-
Object
- Object
- RZotero
- Defined in:
- lib/rzotero.rb
Constant Summary collapse
- BASE_URL =
'https://api.zotero.org'
Instance Attribute Summary collapse
-
#rzotero_error ⇒ Object
Returns the value of attribute rzotero_error.
Instance Method Summary collapse
-
#base ⇒ Object
def user!(user_id) raise TypeError, “user_id must be an Integer” unless user_id.kind_of? Integer @user_id = user_id end.
- #collection(id) ⇒ Object
- #collections ⇒ Object
-
#initialize(user_id, api_key) ⇒ RZotero
constructor
A new instance of RZotero.
-
#item(id) ⇒ Object
Returns a specific item.
- #item_children(id) ⇒ Object
-
#items ⇒ Object
Returns all items for the user.
- #key ⇒ Object
-
#user ⇒ Object
def key!(api_key) raise TypeError, “api_key must be a String” unless user_id.kind_of? String @api_key = api_key end.
Constructor Details
#initialize(user_id, api_key) ⇒ RZotero
Returns a new instance of RZotero.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rzotero.rb', line 11 def initialize(user_id, api_key) @rzotero_error = false begin #TODO need to check if the user_id is numeric; raise TypeError, "user_id must be an Integer" unless user_id.kind_of? Integer raise TypeError, "api_key must be a String" unless api_key.kind_of? String @user_id = user_id @api_key = api_key rescue TypeError @rzotero_error = true end end |
Instance Attribute Details
#rzotero_error ⇒ Object
Returns the value of attribute rzotero_error.
9 10 11 |
# File 'lib/rzotero.rb', line 9 def rzotero_error @rzotero_error end |
Instance Method Details
#base ⇒ Object
def user!(user_id)
raise TypeError, "user_id must be an Integer" unless user_id.kind_of? Integer
@user_id = user_id
end
43 44 45 |
# File 'lib/rzotero.rb', line 43 def base return BASE_URL end |
#collection(id) ⇒ Object
69 70 71 72 |
# File 'lib/rzotero.rb', line 69 def collection(id) url = "#{BASE_URL}/users/#{@user_id}/collections/#{id}?key=#{@api_key}" return Nokogiri.parse(open(url)) end |
#collections ⇒ Object
64 65 66 67 |
# File 'lib/rzotero.rb', line 64 def collections url = "#{BASE_URL}/users/#{@user_id}/collections?key=#{@api_key}" return Nokogiri.parse(open(url)) end |
#item(id) ⇒ Object
Returns a specific item
54 55 56 57 |
# File 'lib/rzotero.rb', line 54 def item(id) url = "#{BASE_URL}/users/#{@user_id}/items/#{id}?key=#{@api_key}" return Nokogiri.parse(open(url)) end |
#item_children(id) ⇒ Object
59 60 61 62 |
# File 'lib/rzotero.rb', line 59 def item_children(id) url = "#{BASE_URL}/users/#{@user_id}/items/#{id}/children?key=#{@api_key}" return Nokogiri.parse(open(url)) end |
#items ⇒ Object
Returns all items for the user
48 49 50 51 |
# File 'lib/rzotero.rb', line 48 def items url = "#{BASE_URL}/users/#{@user_id}/items?key=#{@api_key}" return Nokogiri.parse(open(url)) end |
#key ⇒ Object
25 26 27 |
# File 'lib/rzotero.rb', line 25 def key return @api_key end |
#user ⇒ Object
def key!(api_key)
raise TypeError, "api_key must be a String" unless user_id.kind_of? String
@api_key = api_key
end
34 35 36 |
# File 'lib/rzotero.rb', line 34 def user return @user_id end |