refworks 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +120 -0
- data/lib/refworks.rb +183 -0
- data/lib/refworks/authentication/authentication_request.rb +17 -0
- data/lib/refworks/authentication/authentication_response.rb +3 -0
- data/lib/refworks/authentication/delsess/authentication_delsess_request.rb +20 -0
- data/lib/refworks/authentication/delsess/authentication_delsess_response.rb +3 -0
- data/lib/refworks/authentication/newsess/authentication_newsess_request.rb +37 -0
- data/lib/refworks/authentication/newsess/authentication_newsess_response.rb +10 -0
- data/lib/refworks/authentication/newtempusersess/authentication_newtempusersess_request.rb +21 -0
- data/lib/refworks/authentication/newtempusersess/authentication_newtempusersess_response.rb +9 -0
- data/lib/refworks/authentication/ping/authentication_ping_request.rb +21 -0
- data/lib/refworks/authentication/ping/authentication_ping_response.rb +3 -0
- data/lib/refworks/authentication/userexists/authentication_userexists_request.rb +37 -0
- data/lib/refworks/authentication/userexists/authentication_userexists_response.rb +3 -0
- data/lib/refworks/authors/all/authors_all_request.rb +29 -0
- data/lib/refworks/authors/all/authors_all_response.rb +3 -0
- data/lib/refworks/authors/author.rb +10 -0
- data/lib/refworks/authors/authors_request.rb +23 -0
- data/lib/refworks/authors/authors_response.rb +32 -0
- data/lib/refworks/authors/search/authors_search_request.rb +23 -0
- data/lib/refworks/authors/search/authors_search_response.rb +3 -0
- data/lib/refworks/descriptors/all/descriptors_all_request.rb +21 -0
- data/lib/refworks/descriptors/all/descriptors_all_response.rb +3 -0
- data/lib/refworks/descriptors/descriptor.rb +8 -0
- data/lib/refworks/descriptors/descriptors_request.rb +17 -0
- data/lib/refworks/descriptors/descriptors_response.rb +31 -0
- data/lib/refworks/descriptors/search/descriptors_search_request.rb +24 -0
- data/lib/refworks/descriptors/search/descriptors_search_response.rb +3 -0
- data/lib/refworks/folders/all/folders_all_request.rb +20 -0
- data/lib/refworks/folders/all/folders_all_response.rb +3 -0
- data/lib/refworks/folders/folder.rb +10 -0
- data/lib/refworks/folders/folders_request.rb +17 -0
- data/lib/refworks/folders/folders_response.rb +32 -0
- data/lib/refworks/folders/search/folders_search_request.rb +21 -0
- data/lib/refworks/folders/search/folders_search_response.rb +3 -0
- data/lib/refworks/importfilter/allavailable/importfilter_allavailable_request.rb +20 -0
- data/lib/refworks/importfilter/allavailable/importfilter_allavailable_response.rb +3 -0
- data/lib/refworks/importfilter/allglobal/importfilter_allglobal_request.rb +20 -0
- data/lib/refworks/importfilter/allglobal/importfilter_allglobal_response.rb +3 -0
- data/lib/refworks/importfilter/favorites/importfilter_favorites_request.rb +20 -0
- data/lib/refworks/importfilter/favorites/importfilter_favorites_response.rb +3 -0
- data/lib/refworks/importfilter/importfilter.rb +18 -0
- data/lib/refworks/importfilter/importfilter_request.rb +16 -0
- data/lib/refworks/importfilter/importfilter_response.rb +35 -0
- data/lib/refworks/importfilter/search/importfilter_search_request.rb +22 -0
- data/lib/refworks/importfilter/search/importfilter_search_response.rb +3 -0
- data/lib/refworks/manuscript/all/manuscript_all_request.rb +22 -0
- data/lib/refworks/manuscript/all/manuscript_all_response.rb +13 -0
- data/lib/refworks/manuscript/baseurl/manuscript_baseurl_request.rb +22 -0
- data/lib/refworks/manuscript/baseurl/manuscript_baseurl_response.rb +13 -0
- data/lib/refworks/manuscript/byid/manuscript_byid_request.rb +32 -0
- data/lib/refworks/manuscript/byid/manuscript_byid_response.rb +3 -0
- data/lib/refworks/manuscript/file/manuscript_file_request.rb +22 -0
- data/lib/refworks/manuscript/file/manuscript_file_response.rb +18 -0
- data/lib/refworks/manuscript/folder/manuscript_folder_request.rb +22 -0
- data/lib/refworks/manuscript/folder/manuscript_folder_response.rb +14 -0
- data/lib/refworks/manuscript/manuscript_request.rb +20 -0
- data/lib/refworks/manuscript/manuscript_response.rb +3 -0
- data/lib/refworks/manuscript/mylist/manuscript_mylist_request.rb +21 -0
- data/lib/refworks/manuscript/mylist/manuscript_mylist_response.rb +14 -0
- data/lib/refworks/periodicals/all/periodicals_all_request.rb +21 -0
- data/lib/refworks/periodicals/all/periodicals_all_response.rb +3 -0
- data/lib/refworks/periodicals/periodical.rb +9 -0
- data/lib/refworks/periodicals/periodicals_request.rb +17 -0
- data/lib/refworks/periodicals/periodicals_response.rb +31 -0
- data/lib/refworks/periodicals/search/periodicals_search_request.rb +22 -0
- data/lib/refworks/periodicals/search/periodicals_search_response.rb +3 -0
- data/lib/refworks/properties/encoding/encoding.rb +3 -0
- data/lib/refworks/properties/encoding/properties_encoding_request.rb +20 -0
- data/lib/refworks/properties/encoding/properties_encoding_response.rb +3 -0
- data/lib/refworks/properties/fieldlabels/fieldlabel.rb +13 -0
- data/lib/refworks/properties/fieldlabels/properties_fieldlabels_request.rb +22 -0
- data/lib/refworks/properties/fieldlabels/properties_fieldlabels_response.rb +20 -0
- data/lib/refworks/properties/fieldlabels/reftypeFieldlabels.rb +11 -0
- data/lib/refworks/properties/languages/language.rb +8 -0
- data/lib/refworks/properties/languages/properties_languages_request.rb +22 -0
- data/lib/refworks/properties/languages/properties_languages_response.rb +20 -0
- data/lib/refworks/properties/outputlanguage/outputlanguage.rb +8 -0
- data/lib/refworks/properties/outputlanguage/properties_outputlanguage_request.rb +22 -0
- data/lib/refworks/properties/outputlanguage/properties_outputlanguage_response.rb +20 -0
- data/lib/refworks/properties/properties_request.rb +15 -0
- data/lib/refworks/properties/properties_response.rb +3 -0
- data/lib/refworks/properties/sortlocales/properties_sortlocales_request.rb +20 -0
- data/lib/refworks/properties/sortlocales/properties_sortlocales_response.rb +20 -0
- data/lib/refworks/properties/sortlocales/sortlocale.rb +8 -0
- data/lib/refworks/properties/sourcetypes/properties_sourcetypes_request.rb +21 -0
- data/lib/refworks/properties/sourcetypes/properties_sourcetypes_response.rb +20 -0
- data/lib/refworks/properties/sourcetypes/sourcetype.rb +8 -0
- data/lib/refworks/properties/typelabels/properties_typelabels_request.rb +21 -0
- data/lib/refworks/properties/typelabels/properties_typelabels_response.rb +20 -0
- data/lib/refworks/properties/typelabels/typelabel.rb +8 -0
- data/lib/refworks/reference.rb +526 -0
- data/lib/refworks/reference/get/reference_get_request.rb +21 -0
- data/lib/refworks/reference/get/reference_get_response.rb +7 -0
- data/lib/refworks/reference/reference_request.rb +15 -0
- data/lib/refworks/reference/reference_response.rb +3 -0
- data/lib/refworks/request.rb +50 -0
- data/lib/refworks/response.rb +12 -0
- data/lib/refworks/retrieve/advancesearch/retrieve_advancesearch_request.rb +41 -0
- data/lib/refworks/retrieve/advancesearch/retrieve_advancesearch_response.rb +3 -0
- data/lib/refworks/retrieve/all/retrieve_all_request.rb +21 -0
- data/lib/refworks/retrieve/all/retrieve_all_response.rb +3 -0
- data/lib/refworks/retrieve/author/retrieve_author_request.rb +23 -0
- data/lib/refworks/retrieve/author/retrieve_author_response.rb +3 -0
- data/lib/refworks/retrieve/byid/retrieve_byid_request.rb +22 -0
- data/lib/refworks/retrieve/byid/retrieve_byid_response.rb +3 -0
- data/lib/refworks/retrieve/count/retrieve_count_request.rb +21 -0
- data/lib/refworks/retrieve/count/retrieve_count_response.rb +16 -0
- data/lib/refworks/retrieve/descriptor/retrieve_descriptor_request.rb +22 -0
- data/lib/refworks/retrieve/descriptor/retrieve_descriptor_response.rb +3 -0
- data/lib/refworks/retrieve/dup/retrieve_dup_request.rb +21 -0
- data/lib/refworks/retrieve/dup/retrieve_dup_response.rb +3 -0
- data/lib/refworks/retrieve/folder/retrieve_folder_request.rb +21 -0
- data/lib/refworks/retrieve/folder/retrieve_folder_response.rb +3 -0
- data/lib/refworks/retrieve/modsince/retrieve_modsince_request.rb +23 -0
- data/lib/refworks/retrieve/modsince/retrieve_modsince_response.rb +3 -0
- data/lib/refworks/retrieve/nofolder/retrieve_nofolder_request.rb +20 -0
- data/lib/refworks/retrieve/nofolder/retrieve_nofolder_response.rb +3 -0
- data/lib/refworks/retrieve/periodical/retrieve_periodical_request.rb +22 -0
- data/lib/refworks/retrieve/periodical/retrieve_periodical_response.rb +3 -0
- data/lib/refworks/retrieve/quick/retrieve_quick_request.rb +23 -0
- data/lib/refworks/retrieve/quick/retrieve_quick_response.rb +3 -0
- data/lib/refworks/retrieve/retrieve_request.rb +22 -0
- data/lib/refworks/retrieve/retrieve_response.rb +34 -0
- data/lib/refworks/retrieve/saved/retrieve_saved_request.rb +22 -0
- data/lib/refworks/retrieve/saved/retrieve_saved_response.rb +3 -0
- data/lib/refworks/retrieve/specialfolder/retrieve_specialfolder_request.rb +21 -0
- data/lib/refworks/retrieve/specialfolder/retrieve_specialfolder_response.rb +3 -0
- data/lib/refworks/savedsearch/all/savedsearch_all_request.rb +21 -0
- data/lib/refworks/savedsearch/all/savedsearch_all_response.rb +3 -0
- data/lib/refworks/savedsearch/get/savedsearch_get_request.rb +22 -0
- data/lib/refworks/savedsearch/get/savedsearch_get_response.rb +3 -0
- data/lib/refworks/savedsearch/savedsearch.rb +21 -0
- data/lib/refworks/savedsearch/savedsearch_parameter.rb +18 -0
- data/lib/refworks/savedsearch/savedsearch_parameter_component.rb +10 -0
- data/lib/refworks/savedsearch/savedsearch_request.rb +15 -0
- data/lib/refworks/savedsearch/savedsearch_response.rb +24 -0
- data/lib/refworks/version.rb +3 -0
- metadata +224 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDY3YTk4NGZkNjk5Y2UwZmVlNmM1Y2NkMWJiYTg4MWQ2ODI5ODM3OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OGFjOTc1ODY1ODhkOWUyZDY4OTE0YzIzZjBjMWRkMDhhN2FlNWNiZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzY5MDA5YjQxYjY2ODcwODQ0MTI2Y2VlNTIxZGNmMTc0NTU0NGNlZDljOWNk
|
10
|
+
NzhlZTM1N2M1YzczOTc3ZmJkMDUxZmM1NTZkZWFlZDgyODBjNTQwYzRkZTVk
|
11
|
+
YmQ4ZDFjMTNmNWQzZTkzYjVhYTg4ZDgyOTQwOThlMDM4MDk0YTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTY3ZmZhZTdlMzIxOWIxZWRhYzgwNGRhYmMyNmU5NWJiMjc1YjFkZTlhNTEy
|
14
|
+
NDIxMWQxYjBlZGRjNzIyN2JiZDFkNmJkODgyNjNmODZiMjY0Mjk5NGU2Zjdl
|
15
|
+
ZWE2YTBlM2Y4NjFkODcwYTMzOWViYzQ5ZTU4YTYyNDUxNTg5OTk=
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
refworks-api-ruby
|
2
|
+
=================
|
3
|
+
|
4
|
+
A Ruby interface to the RefWorks API.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
Please see examples/ in the source code repo for sample configuration and usage.
|
10
|
+
|
11
|
+
In particular, please read the comments in refworks-sample.rb, as they contain important information about how
|
12
|
+
to determine the set of parameters needed for each API method call.
|
13
|
+
|
14
|
+
Current Status
|
15
|
+
--------------
|
16
|
+
|
17
|
+
The code is currently ALPHA quality. It has received minimal testing and needs more edge case checking and such.
|
18
|
+
I've opted to release early to see if there is community interest in further development. For a first pass, I
|
19
|
+
focused on implementing (some of) the read portions of the API, so that the code could be used against an
|
20
|
+
RefWorks database which is already populated.
|
21
|
+
|
22
|
+
Class-by-class status and notes are below.
|
23
|
+
|
24
|
+
Attachments
|
25
|
+
- Nothing implemented
|
26
|
+
|
27
|
+
Authentication
|
28
|
+
- delsess, newsess, newtempusersess, ping, userexists are implemented.
|
29
|
+
- newrefsharesess not implemented.
|
30
|
+
|
31
|
+
Authors,Descriptors,Periodicals,Folders
|
32
|
+
- all and search are implemented.
|
33
|
+
- addref (GET), addref (POST), clear, create, delete, edit, removeref (GET), removeref (POST) are not implemented.
|
34
|
+
- note that in the code, these are broken out into four different classes.
|
35
|
+
|
36
|
+
Batch
|
37
|
+
- Nothing implemented.
|
38
|
+
|
39
|
+
Deleted
|
40
|
+
- Nothing implemented.
|
41
|
+
|
42
|
+
ImportFilter
|
43
|
+
- allavailable, allglobal, favorites, search are implemented.
|
44
|
+
- savelastused is not implemented.
|
45
|
+
|
46
|
+
Manuscript
|
47
|
+
- all, baseurl, byid, file, folder, mylist are implemented.
|
48
|
+
- openoffice, word, xml are not implemented.
|
49
|
+
|
50
|
+
MyList
|
51
|
+
- Nothing implemented.
|
52
|
+
|
53
|
+
OutputStyle
|
54
|
+
- Nothing implemented.
|
55
|
+
|
56
|
+
Properties [Complete]
|
57
|
+
- encoding, fieldlabels, languages, outputlanguage, sortlocales, sourcetypes, typelabels are implemented.
|
58
|
+
|
59
|
+
PubMed
|
60
|
+
- Nothing implemented.
|
61
|
+
|
62
|
+
Reference
|
63
|
+
- get implemented.
|
64
|
+
- add, addcomment, delete (GET), delete (POST), deletecomment, edit, editcomment, globaledit, import,
|
65
|
+
importendnote, importpreview, openurl not implemented.
|
66
|
+
|
67
|
+
Retrieve
|
68
|
+
- advancesearch, all, author, byid, count, descriptor, dup, folder, modsince, nofolder, periodical, quick,
|
69
|
+
saved, specialfolder implemented.
|
70
|
+
- byid (POST), openurl not implemented.
|
71
|
+
|
72
|
+
RSS
|
73
|
+
- Nothing implemented.
|
74
|
+
|
75
|
+
SavedSearch
|
76
|
+
- all, get implemented.
|
77
|
+
- add, delete, edit not implemented.
|
78
|
+
|
79
|
+
ShareProperties
|
80
|
+
- Nothing implemented.
|
81
|
+
|
82
|
+
Subscriber
|
83
|
+
- Nothing implemented.
|
84
|
+
|
85
|
+
SubscriberPrefs
|
86
|
+
- Nothing implemented.
|
87
|
+
|
88
|
+
User
|
89
|
+
- Nothing implemented.
|
90
|
+
|
91
|
+
Utility
|
92
|
+
- Nothing implemented.
|
93
|
+
|
94
|
+
Z39
|
95
|
+
- Nothing implemented.
|
96
|
+
|
97
|
+
Basic Code Flow
|
98
|
+
---------------
|
99
|
+
|
100
|
+
1. The user instantiates a Refworks client (Refworks.new). Refworks sets up a session via the API as part of
|
101
|
+
initialization.
|
102
|
+
2. The user issues an API request by invoking Refworks.request.
|
103
|
+
3. Refworks.request resolves and instantiates the Request class for the specific API method being called
|
104
|
+
(e.g. RetrieveAllRequest).
|
105
|
+
4. Refworks.request uses the method-specific Request class (for method-specific parameters) and the to assemble
|
106
|
+
the query string, determine the URL and HTTP verb to use, and issues the request.
|
107
|
+
5. Refworks.request receives the response and instantiates the method-specific Response class
|
108
|
+
(e.g. RetrieveAllResponse).
|
109
|
+
6. The user accesses the method-specific Response class to retrieve the data and/or return codes for the operation.
|
110
|
+
|
111
|
+
Each Response class returns its own set of data - for example, a call to the all method of the retrieve class
|
112
|
+
returns a set of Reference objects, whereas a call to the search method of the authors class returns a set of
|
113
|
+
Author objects. See the documentation for each class and method for full details.
|
114
|
+
|
115
|
+
Useful Links
|
116
|
+
------------
|
117
|
+
|
118
|
+
RefWorks API Reference: http://rwt.refworks.com/rwapireference/
|
119
|
+
RefWorks Tagged Format Reference: http://www.refworks.com/rwathens/help/RefWorks_Tagged_Format.htm
|
120
|
+
|
data/lib/refworks.rb
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/..')
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
# This will recursively load all child classes - done this way
|
6
|
+
# because there are many, many child classes, and makes it easier
|
7
|
+
# to keep adding support for more parts of the refworks API
|
8
|
+
require 'httparty'
|
9
|
+
require 'cgi'
|
10
|
+
require 'pp'
|
11
|
+
require 'require_all'
|
12
|
+
require_rel 'refworks'
|
13
|
+
|
14
|
+
# This is the main entry class to the API. It handles session attainment, assembles and
|
15
|
+
# issues requests, and routes responses to the appropriate response object.
|
16
|
+
# @api public
|
17
|
+
class Refworks
|
18
|
+
include HTTParty
|
19
|
+
|
20
|
+
attr_reader :api_url, :access_key, :secret_key, :login_name, :password, :group_code, :id, :sess
|
21
|
+
|
22
|
+
# Create a new Refworks client instance.
|
23
|
+
# @example
|
24
|
+
# rwc = Refworks.new({:access_key => 'YOUR_ACCESS_KEY_HERE',
|
25
|
+
# :secret_key => 'YOUR_SECRET_KEY_HERE',
|
26
|
+
# :id => '', # Either id -or- group_code is needed
|
27
|
+
# :group_code => 'YOUR_GROUP_CODE_HERE',
|
28
|
+
# :login_name => 'YOUR_LOGIN_NAME_HERE',
|
29
|
+
# :password => 'YOUR_PASSWORD_HERE',
|
30
|
+
# :api_url => 'https://www.refworks.com/api2/',
|
31
|
+
# :httparty_debug => 0, # or a true value to turn on httparty debug output
|
32
|
+
# :httparty_timeout => 300, # may need to set higher if your database is very large
|
33
|
+
# })
|
34
|
+
# @param [Hash] params The configuration settings for this instance of the Refworks API client. See example above
|
35
|
+
# for list of possible/required keys.
|
36
|
+
def initialize(params)
|
37
|
+
|
38
|
+
# configure HTTParty using its debug_output and default_timeout methods if user passed in values for these
|
39
|
+
# (otherwise it uses HTTParty defaults)
|
40
|
+
if params[:httparty_debug]
|
41
|
+
self.class.debug_output $stderr
|
42
|
+
end
|
43
|
+
if params[:httparty_timeout]
|
44
|
+
self.class.default_timeout(params[:httparty_timeout])
|
45
|
+
end
|
46
|
+
|
47
|
+
# populate the attributes
|
48
|
+
@api_url = params[:api_url]
|
49
|
+
@access_key = params[:access_key]
|
50
|
+
@secret_key = params[:secret_key]
|
51
|
+
@login_name = params[:login_name]
|
52
|
+
@password = params[:password]
|
53
|
+
@group_code = params[:group_code]
|
54
|
+
@id = params[:id]
|
55
|
+
|
56
|
+
# probably should check here that I have the minimal set of required attributes to continue
|
57
|
+
|
58
|
+
# Can't do much without a session, so get one now
|
59
|
+
# May need to refactor this - there are parts of the API that don't strictly need a session
|
60
|
+
if (@group_code)
|
61
|
+
response = request('authentication', 'newsess',
|
62
|
+
{
|
63
|
+
:login_name => @login_name,
|
64
|
+
:group_code => @group_code,
|
65
|
+
:password => @password,
|
66
|
+
}
|
67
|
+
)
|
68
|
+
else
|
69
|
+
response = request('authentication', 'newsess',
|
70
|
+
{
|
71
|
+
:login_name => @login_name,
|
72
|
+
:id => @id,
|
73
|
+
:password => @password,
|
74
|
+
}
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Grab the session string.
|
79
|
+
@sess = response.sess
|
80
|
+
|
81
|
+
# Need some error checking here
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# Returns appropriate request class name constant given class and method strings
|
87
|
+
#
|
88
|
+
# @param [String] class_name The class name being called in the Refworks API
|
89
|
+
# @param [String] method_name The method name being called in the Refworks API
|
90
|
+
# @return [Object] The class constant for the request class
|
91
|
+
def resolve_request_class(class_name, method_name)
|
92
|
+
Object.const_get([class_name, method_name, 'Request'].collect(&:capitalize).join)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Produce appropriate response class name constant given class and method strings
|
96
|
+
#
|
97
|
+
# @param [String] class_name The class name being called in the Refworks API
|
98
|
+
# @param [String] method_name The method name being called in the Refworks API
|
99
|
+
# @return [Object] The class constant for the response class
|
100
|
+
def resolve_response_class(class_name, method_name)
|
101
|
+
Object.const_get([class_name, method_name, 'Response'].collect(&:capitalize).join)
|
102
|
+
end
|
103
|
+
|
104
|
+
protected
|
105
|
+
|
106
|
+
# Combines the request, signature and session query parameters, CGI-escaping
|
107
|
+
# them in the process, and returns a query string.
|
108
|
+
#
|
109
|
+
# @param [Hash] request_params Request-specific parameters, including the class, the method, and any method params
|
110
|
+
# @param [Hash] signature_params The signature parameters for this call
|
111
|
+
# @return [String] The fully-formed and escaped query string
|
112
|
+
def generate_query_params(request_params, signature_params)
|
113
|
+
|
114
|
+
# create a CGI-escaped query string fragment out of all of the request-specific parameters
|
115
|
+
request_param_string = request_params.collect { |key, value|
|
116
|
+
# sometimes a method parameter is an array - like multiple id's for the retrieve->byid id parameter
|
117
|
+
if value.is_a?(Array)
|
118
|
+
value.collect { |x|
|
119
|
+
x = CGI.escape(x.to_s)
|
120
|
+
"#{key}=#{x}"}.join("&")
|
121
|
+
# but most method parameters are scalar
|
122
|
+
else
|
123
|
+
value = CGI.escape(value.to_s)
|
124
|
+
"#{key}=#{value}"
|
125
|
+
end
|
126
|
+
}.join("&")
|
127
|
+
|
128
|
+
# create a CGI-escaped query string fragment out of the signature pieces
|
129
|
+
signature_param_string = signature_params.collect { |key, value|
|
130
|
+
value = CGI.escape(value.to_s)
|
131
|
+
"#{key}=#{value}"}.join("&")
|
132
|
+
|
133
|
+
# create a CGI-escaped query string fragment out of the session
|
134
|
+
# Session string handling needs to be more elegant. Too hard coded/inflexible
|
135
|
+
if sess
|
136
|
+
session_param_string = "sess=" + CGI.escape(sess)
|
137
|
+
else
|
138
|
+
session_param_string = ''
|
139
|
+
end
|
140
|
+
|
141
|
+
# combine all and return
|
142
|
+
request_param_string + '&' + signature_param_string + '&' + session_param_string
|
143
|
+
end
|
144
|
+
|
145
|
+
public
|
146
|
+
|
147
|
+
# Issue a request to the Refworks API and use the response to construct a Response object. This method is the
|
148
|
+
# primary way that users interact with the Refworks API.
|
149
|
+
# @example
|
150
|
+
# response = rwc.request('retrieve', 'quick', {:search => "Jones"})
|
151
|
+
# @param [String] class_name The class name being called in the Refworks API
|
152
|
+
# @param [String] method_name The method name being called in the Refworks API
|
153
|
+
# @param [Hash] method_params A Hash containing a method-specific set of parameters. See the documentation for each
|
154
|
+
# method for more info. This can be omitted in the case of a method that does not require any parameters.
|
155
|
+
# @return [Object] A child object of the Response object (specific to the particular API call being made)
|
156
|
+
def request(class_name, method_name, method_params = {})
|
157
|
+
|
158
|
+
# Resolve the request class and use it to retrieve the request-specific query parameters
|
159
|
+
request_class = resolve_request_class(class_name, method_name)
|
160
|
+
request_info = request_class.generate_request_info(method_params)
|
161
|
+
|
162
|
+
# Generate a signature for this call
|
163
|
+
signature_params = request_class.generate_signature(class_name, access_key, secret_key)
|
164
|
+
|
165
|
+
# Put it all together to complete the query string
|
166
|
+
query_params = self.generate_query_params(request_info[:params], signature_params)
|
167
|
+
|
168
|
+
# Some parts of the API use a different URL than the base URL, so we check for that here and assemble
|
169
|
+
# the entire request URL
|
170
|
+
url = (method_params[:base_url] || api_url) + "?#{query_params}"
|
171
|
+
|
172
|
+
# make the request
|
173
|
+
if request_class.http_request_verb == 'POST'
|
174
|
+
raw_response = self.class.post(url, :body => request_info[:body], :headers => request_info[:headers])
|
175
|
+
else
|
176
|
+
raw_response = self.class.get(url)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Resolve, instantiate and return the response class
|
180
|
+
response_class = resolve_response_class(class_name, method_name)
|
181
|
+
response_class.new(raw_response)
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AuthenticationRequest < Request
|
2
|
+
|
3
|
+
def self.call_class
|
4
|
+
'authentication'
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.generate_class_params(params)
|
8
|
+
# handle params common to all Retrieve calls
|
9
|
+
class_name = call_class()
|
10
|
+
|
11
|
+
# query parameters common to all Retrieve calls
|
12
|
+
{
|
13
|
+
:class => class_name,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class AuthenticationDelsessRequest < AuthenticationRequest
|
2
|
+
def self.call_method
|
3
|
+
'delsess'
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.generate_request_info(params)
|
7
|
+
|
8
|
+
# get common Authentication parameters
|
9
|
+
class_params = generate_class_params(params)
|
10
|
+
|
11
|
+
# query parameters for the ping call
|
12
|
+
method_params = { :method => call_method,
|
13
|
+
}
|
14
|
+
|
15
|
+
query_string_params = class_params.merge(method_params)
|
16
|
+
|
17
|
+
# return the request info
|
18
|
+
{:params => query_string_params}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class AuthenticationNewsessRequest < AuthenticationRequest
|
2
|
+
|
3
|
+
def self.call_method
|
4
|
+
'newsess'
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.http_request_verb
|
8
|
+
'POST'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.generate_request_info(params)
|
12
|
+
|
13
|
+
class_name = call_class()
|
14
|
+
method_name = call_method()
|
15
|
+
|
16
|
+
# query parameters for the newsess call
|
17
|
+
query_string_params = {
|
18
|
+
:class => class_name,
|
19
|
+
:method => method_name,
|
20
|
+
}
|
21
|
+
|
22
|
+
# Construct the XML payload for the newsess call.
|
23
|
+
login_name = params[:login_name]
|
24
|
+
password = params[:password]
|
25
|
+
group_code = params[:group_code]
|
26
|
+
|
27
|
+
message_body = <<-EOS
|
28
|
+
<RWRequest class="authentication" method="newsess">
|
29
|
+
<AcctInfo loginName="#{login_name}" groupCode="#{group_code}" password="#{password}"></AcctInfo>
|
30
|
+
</RWRequest>
|
31
|
+
EOS
|
32
|
+
|
33
|
+
# return the request info
|
34
|
+
{:params => query_string_params, :body => message_body, :headers => {'Content-type' => 'text/xml'}}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class AuthenticationNewtempusersessRequest < AuthenticationRequest
|
2
|
+
def self.call_method
|
3
|
+
'newtempusersess'
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.generate_request_info(params)
|
7
|
+
|
8
|
+
# get common Authentication parameters
|
9
|
+
class_params = generate_class_params(params)
|
10
|
+
|
11
|
+
# query parameters for the newtempusersess call
|
12
|
+
method_params = { :method => call_method,
|
13
|
+
}
|
14
|
+
|
15
|
+
query_string_params = class_params.merge(method_params)
|
16
|
+
|
17
|
+
# return the request info
|
18
|
+
{:params => query_string_params}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|