forked from spotzero/wsdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsdata.api.php
180 lines (178 loc) · 5.52 KB
/
wsdata.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* API Documentation for WSData
*/
/**
* List of data processors available for parsing web service data.
*
* Processors have two components:
* - data parsing format
* - data output structure
*
* Data parsing format refers to the type of data this processor can parse.
* For example json, xml, ical, etc...
*
* The output structure refers to the Drupal object which can be fed by
* the parsed data. Your options are:
*
* - fields
* - form
* - data
*
* Fields imply that this processor can feed information into wsfields.
* Form is for wsbeans, and any other object which renders Form API data.
* Data is to simply return the raw parsed data. Meaning if you pass in
* a JSON array for example, you'll be returned a PHP array representation
* of that JSON data.
*
* The return array is keyed on the class name of the processor (please use
* proper class casing. Our naming scheme is from the legacy class formats
* in Drupal)
*
* Be sure to include your classes in the .info file if they aren't stored
* in your .module file
*
* @return array
* Returns an array of processor info.
* @see wsdata.info
*/
function hook_wsconfig_processor_info() {
return array(
'WsDataSimpleXmlProcessor' => array(
'fields' => array(
'list_boolean' => t('WSData Simple XML Processor'),
'text_with_summary' => t('WSData Simple XML Processor'),
'text' => t('WSData Simple XML Processor'),
),
'data' => t('WSData Simple XML Processor'),
'form' => t('WSData Simple XML Form API Processor'),
),
'WsDataSimpleJsonProcessor' => array(
'fields' => array(
'list_boolean' => t('WSData Simple JSON Processor'),
'text_with_summary' => t('WSData Simple JSON Processor'),
'text' => t('WSData Simple JSON Processor'),
),
'data' => t('WSData Simple JSON Processor'),
),
);
}
/**
* List of language handler plugins
*
* Adds to the list of available language handling plugins.
* The plugins do nothing on their own. They simply define
* a set of functionality which the WsConnector implementations
* can reference.
*
* Language plugins define how multilingual data is requested
* from a web service. There are two classes of plugins:
*
* 1. Single request plugins
* 2. Multi request plugins
*
* Single request plugins mean that all language data is captured
* in a single request. Usually this means the data processor
* is responsible for parsing keyed values in the return data
* per language. This is the default language handler.
*
* Multi request handlers imply that multiple web service requests
* are required to capture all languages available. The default
* methods defined for this are "header", "argument", "path" and "uri".
* It is the responsibility of the WsConnector to support these plugins.
*
* You may define your own plugins if you have a particularly unique
* language request mechanism (ex: post body data)
*
* For an example implementation
* @see http://drupal.org/project/restclient
*/
function hook_wsdata_language_plugin() {
return array(
/**
* Header language plugin
*
* The header plugin adds a header value to the request
* which sets the language of the request.
*
* The value is the language key of the enabled languages on your site.
* You may override this in the settings array.
*/
'header' => array(
'settings' => array(
'name' => 'Accept-Language',
'en' => 'en', // Each language plugin will list the enabled languages on your site to set values when requesting data for that given language.
'fr' => 'fr',
),
'form' => 'wsdata_language_plugin_header_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
/**
* Argument language plugin
*
* The argument plugin adds a query string argument (ex: ?lang=en).
*/
'argument' => array(
'settings' => array(
'name' => 'lang',
'en' => 'en',
'fr' => 'fr',
),
'form' => 'wsdata_language_plugin_argument_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
/**
* Path language plugin
*
* The path plugin puts the language into the request path at the given position.
* Ex:
* position = 0, http://example.com/en/my/webservice/request
* position = 2, http://example.com/my/webservice/en/request
*
* By default, it acts as a path prefix. (i.e. position 0)
*/
'path' => array(
'settings' => array(
'position' => 0,
'en' => 'en',
'fr' => 'fr',
),
'form' => 'wsdata_language_plugin_path_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
/**
* URI language plugin
*
* The URI plugin changes the URI to a different one based on the requesting language.
*/
'uri' => array(
'settings' => array(
'en' => 'example.com',
'fr' => 'fr.example.com',
),
'form' => 'wsdata_language_plugin_path_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
/**
* Default language plugin
*
* By default, do nothing. Assume the WsProcessor will have all the language data
* in a single request.
*/
'default' => array(
'settings' => array(),
'form' => 'wsdata_language_plugin_default_form',
'file' => 'wsdata.admin',
'file type' => 'inc',
'module' => 'wsdata',
),
);
}