mendeley 0.0.2
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/mendeley.rb +10 -0
- data/lib/mendeley/public_api.rb +52 -0
- data/lib/mendeley/version.rb +3 -0
- data/mendeley.gemspec +26 -0
- data/spec/mendeley/public_api_spec.rb +45 -0
- data/spec/mendeley_spec.rb +19 -0
- data/spec/spec_helper.rb +10 -0
- data/watchr.rb +39 -0
- metadata +135 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/mendeley.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Mendeley
|
2
|
+
module API
|
3
|
+
def request(sub_url, params = nil)
|
4
|
+
request = build_request_url(sub_url ,params)
|
5
|
+
JSON.parse(RestClient.get(request))
|
6
|
+
end
|
7
|
+
|
8
|
+
def build_request_url(sub_url, params = nil )
|
9
|
+
request_url = File.join(self.base_url, sub_url)
|
10
|
+
param_string = "?consumer_key=#{Mendeley.consumer_key}"
|
11
|
+
if params
|
12
|
+
params.each do |key,value|
|
13
|
+
param_string << "&#{key}=#{value}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
request_url.concat(param_string)
|
17
|
+
end
|
18
|
+
private :build_request_url
|
19
|
+
|
20
|
+
#Wrapper for the public /documents/ domain on mendeley
|
21
|
+
#see http://apidocs.mendeley.com/home/public-resources
|
22
|
+
#All of the following actions will take place on the
|
23
|
+
#documents namespace of the API.
|
24
|
+
#
|
25
|
+
#EX// to search all documents for "hello world" you would do
|
26
|
+
# Mendeley::API::Documents.search("hello world")
|
27
|
+
# All Responses will be a ruby hash created by parsing the
|
28
|
+
# response json from the mendeley api
|
29
|
+
class Documents
|
30
|
+
extend API
|
31
|
+
|
32
|
+
@base_url = "http://api.mendeley.com/oapi/documents/"
|
33
|
+
|
34
|
+
def self.base_url
|
35
|
+
@base_url
|
36
|
+
end
|
37
|
+
|
38
|
+
#Search all documents using the public API for the given term
|
39
|
+
def self.search(term)
|
40
|
+
request(File.join("search", URI.escape(term)))
|
41
|
+
end
|
42
|
+
|
43
|
+
#Fetch the detailed description of the document from mendeley
|
44
|
+
def self.document_details(doc_id)
|
45
|
+
unless doc_id.is_a?(String)
|
46
|
+
raise "Invalid argument type. Must be a string"
|
47
|
+
end
|
48
|
+
request(File.join("details", URI.escape(doc_id)))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/mendeley.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mendeley/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mendeley"
|
7
|
+
s.version = Mendeley::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ryan Weald"]
|
10
|
+
s.email = ["ryan@weald.com"]
|
11
|
+
s.homepage = "http://github.com/rweald/mendeley"
|
12
|
+
s.summary = %q{A simple ruby wrapper for the mendeley api}
|
13
|
+
s.description = %q{A simple ruby wrapper for the mendeley api}
|
14
|
+
|
15
|
+
s.rubyforge_project = "mendeley"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
s.add_development_dependency 'mocha'
|
24
|
+
s.add_dependency 'rest-client'
|
25
|
+
s.add_dependency 'yajl-ruby'
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
include Mendeley::API
|
3
|
+
|
4
|
+
describe "Mendeley" do
|
5
|
+
describe "API" do
|
6
|
+
describe "Documents" do
|
7
|
+
it "should extend all the API module methods" do
|
8
|
+
Mendeley::API::Documents.singleton_methods.include?("request").should be_true
|
9
|
+
end
|
10
|
+
it "should have a base_url" do
|
11
|
+
Documents.base_url.should == "http://api.mendeley.com/oapi/documents/"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".build_request_url" do
|
15
|
+
it "should return /search/<terms>" do
|
16
|
+
Documents.send(:build_request_url, "/search").should == "http://api.mendeley.com/oapi/documents/search?consumer_key="
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".search" do
|
21
|
+
it "should search documents for the string for marcio" do
|
22
|
+
response = JSON.generate({:result => "success"})
|
23
|
+
RestClient.expects(:get).with() do |request|
|
24
|
+
request.should == "http://api.mendeley.com/oapi/documents/search/marcio%20von%20muhlen?consumer_key="
|
25
|
+
end.returns(response)
|
26
|
+
Documents.search("marcio von muhlen")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".document_details" do
|
31
|
+
it "should return the details of a document do" do
|
32
|
+
response = JSON.generate({:result => "success"})
|
33
|
+
RestClient.expects(:get).with() do |request|
|
34
|
+
request.should == "http://api.mendeley.com/oapi/documents/details/15?consumer_key="
|
35
|
+
end.returns(response)
|
36
|
+
Documents.document_details("15")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should throw an exception if the id is not a string" do
|
40
|
+
lambda{Documents.document_details(15)}.should raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Mendeley" do
|
4
|
+
it "should have a version" do
|
5
|
+
Mendeley::VERSION.should be
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have a API submodule" do
|
9
|
+
Mendeley.constants.include?("API")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a consumer key" do
|
13
|
+
Mendeley.singleton_methods.include?("consumer_key")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have nil as the initial consumer key value" do
|
17
|
+
Mendeley.consumer_key.should be_nil
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/watchr.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
first_run = true
|
2
|
+
def run_test_suite
|
3
|
+
puts ("rspec spec/")
|
4
|
+
result = %x[rspec spec/]
|
5
|
+
send_growl_notification(result)
|
6
|
+
puts result
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse_results(result_string)
|
10
|
+
error = false
|
11
|
+
if result_hash = (result_string.match(/([1-9]+) example[s]*, ([0-9]+) failure[s]*/))
|
12
|
+
result_hash = result_hash.captures
|
13
|
+
else
|
14
|
+
error = true
|
15
|
+
result_hash = [0,0]
|
16
|
+
end
|
17
|
+
{:failures => result_hash[1], :number_tests => result_hash[0], :error => error}
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_growl_notification(result_text)
|
21
|
+
result_hash = parse_results(result_text)
|
22
|
+
title = "Test Results"
|
23
|
+
unless result_hash[:error]
|
24
|
+
message = "#{result_hash[:number_tests]} examples, #{result_hash[:failures]} failures"
|
25
|
+
else
|
26
|
+
message = "An Error Occured in your code"
|
27
|
+
end
|
28
|
+
system(%Q[growlnotify -t "#{title}" -m "#{message}"])
|
29
|
+
end
|
30
|
+
|
31
|
+
#watch the lib directory and if anything changes run the whole test suite
|
32
|
+
watch('lib/(.*)\.rb'){ run_test_suite}
|
33
|
+
watch('spec/*') {run_test_suite}
|
34
|
+
|
35
|
+
#run the full test suite when watchr is first run
|
36
|
+
if first_run
|
37
|
+
run_test_suite
|
38
|
+
first_run = false
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mendeley
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ryan Weald
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-01 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mocha
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rest-client
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: yajl-ruby
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
77
|
+
description: A simple ruby wrapper for the mendeley api
|
78
|
+
email:
|
79
|
+
- ryan@weald.com
|
80
|
+
executables: []
|
81
|
+
|
82
|
+
extensions: []
|
83
|
+
|
84
|
+
extra_rdoc_files: []
|
85
|
+
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- Gemfile
|
89
|
+
- Rakefile
|
90
|
+
- lib/mendeley.rb
|
91
|
+
- lib/mendeley/public_api.rb
|
92
|
+
- lib/mendeley/version.rb
|
93
|
+
- mendeley.gemspec
|
94
|
+
- spec/mendeley/public_api_spec.rb
|
95
|
+
- spec/mendeley_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- watchr.rb
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: http://github.com/rweald/mendeley
|
100
|
+
licenses: []
|
101
|
+
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project: mendeley
|
128
|
+
rubygems_version: 1.3.7
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: A simple ruby wrapper for the mendeley api
|
132
|
+
test_files:
|
133
|
+
- spec/mendeley/public_api_spec.rb
|
134
|
+
- spec/mendeley_spec.rb
|
135
|
+
- spec/spec_helper.rb
|