Class: RZotero

Inherits:
Object
  • Object
show all
Defined in:
lib/rzotero.rb

Constant Summary collapse

BASE_URL =
'https://api.zotero.org'

Instance Attribute Summary collapse

Instance Method Summary collapse

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_errorObject

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

#baseObject

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

#collectionsObject



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

#itemsObject

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

#keyObject



25
26
27
# File 'lib/rzotero.rb', line 25

def key
  return @api_key
end

#userObject

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