freelancer 0.1.0 → 0.1.1

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.
@@ -30,6 +30,91 @@ module Freelancer
30
30
 
31
31
  end
32
32
 
33
+ # Place a bid on a project
34
+ #
35
+ # Valid parameters are:
36
+ # - project_id: the id of the project to bid on
37
+ # - amount: the amount of money to offer taking the project for
38
+ # - description: the bid description
39
+ # - days: the estimated number of days to complete the project
40
+ # - notify_on_underbid: if notifications should be send when someone bids lower than this bid
41
+ # - highlighted: if this bid is highlighted or not
42
+ # - milestone: declares the initial milestone percentage for the bid
43
+ def bid_on_project(*args)
44
+
45
+ params = extract_params(args)
46
+
47
+ # Execute the service call
48
+ result = api_get("/Freelancer/placeBidOnProject.json", build_api_params({
49
+ :projectid => params[:project_id],
50
+ :amount => params[:amount],
51
+ :description => params[:description],
52
+ :days => params[:days],
53
+ :notificationStatus => params[:notify_on_underbid],
54
+ :highlighted => params[:highlighted],
55
+ :milestone => params[:milestone]
56
+ }))
57
+
58
+ # Parse and return the response
59
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
60
+
61
+ end
62
+
63
+ # Retract a bid from a project
64
+ #
65
+ # Valid parameters are:
66
+ # - project_id: the id of the project to withdraw bid from
67
+ def retract_bid_from_project(*args)
68
+
69
+ params = extract_params(args)
70
+
71
+ # Execute the service call
72
+ result = api_get("/Freelancer/retractBidFromProject.json", build_api_params({
73
+ :projectid => params[:project_id]
74
+ }))
75
+
76
+ # Parse and return the response
77
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
78
+
79
+ end
80
+
81
+ # Accept a won bid
82
+ #
83
+ # Valid parameters are:
84
+ # - project_id: the id of the project to accept the offer on
85
+ def accept_won_bid(*args)
86
+
87
+ params = extract_params(args)
88
+
89
+ # Execute the service call
90
+ result = api_get("/Freelancer/acceptBidWon.json", build_api_params({
91
+ :projectid => params[:project_id]
92
+ }))
93
+
94
+ # Parse and return the response
95
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
96
+
97
+ end
98
+
99
+ # Reject a won bid
100
+ #
101
+ # Valid parameters are:
102
+ # - project_id: the id of the project to reject the offer on
103
+ def reject_won_bid(*args)
104
+
105
+ params = extract_params(args)
106
+
107
+ # Execute the service call
108
+ result = api_get("/Freelancer/acceptBidWon.json", build_api_params({
109
+ :projectid => params[:project_id],
110
+ :state => 0
111
+ }))
112
+
113
+ # Parse and return the response
114
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
115
+
116
+ end
117
+
33
118
  end
34
119
  end
35
120
  end
@@ -83,6 +83,48 @@ module Freelancer
83
83
 
84
84
  end
85
85
 
86
+ # Send a private message to another user
87
+ #
88
+ # Valid parameters are:
89
+ # - project_id: the id of the project to send message for
90
+ # - text: the text of the message to send
91
+ # - user_id: the id of the user to send the message to
92
+ # - username: the username of the user to send the message to
93
+ def send_message(*args)
94
+
95
+ params = extract_params(args)
96
+
97
+ # Execute the service call
98
+ result = api_get("/Message/sendMessage.json", build_api_params({
99
+ :projectid => params[:project_id],
100
+ :messagetext => params[:text],
101
+ :userid => params[:user_id],
102
+ :username => params[:username]
103
+ }))
104
+
105
+ # Parse and return the response
106
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
107
+
108
+ end
109
+
110
+ # Mark a message as read
111
+ #
112
+ # Valid parameters are:
113
+ # - message_id: the id of the message to mark as read
114
+ def mark_message_as_read(*args)
115
+
116
+ params = extract_params(args)
117
+
118
+ # Execute the service call
119
+ result = api_get("/Message/markMessageAsRead.json", build_api_params({
120
+ :id => params[:message_id]
121
+ }))
122
+
123
+ # Parse and return the response
124
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
125
+
126
+ end
127
+
86
128
  end
87
129
  end
88
130
  end
@@ -117,6 +117,190 @@ module Freelancer
117
117
 
118
118
  end
119
119
 
120
+ # Request withdrawal of funds
121
+ #
122
+ # Valid parameters are:
123
+ # - amount: the amount of money to withdraw
124
+ # - method: the withdrawal method (paypal, moneybooker, wire, paynoneer)
125
+ # - wire_comment: withdrawal comment for wire transfer
126
+ # - paypal_email: paypal account to withdraw to
127
+ # - moneybooker_account: moneybooker account to withdraw to
128
+ # - description: description for wire transfer withdrawal
129
+ # - country_code: country code for wire transfer withdrawal
130
+ def request_withdrawal(*args)
131
+
132
+ params = extract_params(args)
133
+
134
+ # Execute the service call
135
+ result = api_get("/Payment/requestWithdrawal.json", build_api_params({
136
+ :amount => params[:amount],
137
+ :method => params[:method],
138
+ :additionaltext => params[:wire_comment],
139
+ :paypalemail => params[:paypal_email],
140
+ :mb_account => params[:moneybooker_account],
141
+ :description => params[:description],
142
+ :country_code => params[:country_code]
143
+ }))
144
+
145
+ # Parse and return the response
146
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
147
+
148
+ end
149
+
150
+ # Create a new milestone payment
151
+ #
152
+ # Valid parameters are:
153
+ # - project_id: the id of the project to create the payment for
154
+ # - amount: the amount of money to add to the milestone payment
155
+ # - user_id: the id of the user to make out the payment to
156
+ # - username: the username of the user to make out the payment to
157
+ # - comment: the comment of the payment
158
+ # - type: the milestone payment type (partial, full or other)
159
+ def create_milestone_payment(*args)
160
+
161
+ params = extract_params(args)
162
+
163
+ # Execute the service call
164
+ result = api_get("/Payment/createMilestonePayment.json", build_api_params({
165
+ :projectid => params[:project_id],
166
+ :amount => params[:amount],
167
+ :touserid => params[:user_id],
168
+ :tousername => params[:username],
169
+ :reasontext => params[:comment],
170
+ :reasontype => params[:type]
171
+ }))
172
+
173
+ # Parse and return the response
174
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
175
+
176
+ end
177
+
178
+ # Transfer money to another user
179
+ #
180
+ # Valid parameters are:
181
+ # - project_id: the id of the project to transfer money for
182
+ # - amount: the amount of money to transfer
183
+ # - user_id: the id of the user to transfer the money to
184
+ # - username: the username of the user to transfer the money to
185
+ # - comment: the comment of the transfer
186
+ # - type: the transfer type (partial, full or other)
187
+ def transfer_money(*args)
188
+
189
+ params = extract_params(args)
190
+
191
+ # Execute the service call
192
+ result = api_get("/Payment/transferMoney.json", build_api_params({
193
+ :projectid => params[:project_id],
194
+ :amount => params[:amount],
195
+ :touserid => params[:user_id],
196
+ :tousername => params[:username],
197
+ :reasontext => params[:comment],
198
+ :reasontype => params[:type]
199
+ }))
200
+
201
+ # Parse and return the response
202
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
203
+
204
+ end
205
+
206
+ # Cancel a money withdrawal request
207
+ #
208
+ # Valid parameters are:
209
+ # - withdrawal_id: the id of the withdrawal to cancel
210
+ def cancel_withdrawal(*args)
211
+
212
+ params = extract_params(args)
213
+
214
+ # Execute the service call
215
+ result = api_get("/Payment/requestCancelWithdrawal.json", build_api_params({
216
+ :withdrawalid => params[:withdrawal_id]
217
+ }))
218
+
219
+ # Parse and return the response
220
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
221
+
222
+ end
223
+
224
+ # Cancel a milestone payment
225
+ #
226
+ # Valid parameters are:
227
+ # - transaction_id: the id of the milestone transaction to cancel
228
+ def cancel_milestone(*args)
229
+
230
+ params = extract_params(args)
231
+
232
+ # Execute the service call
233
+ result = api_get("/Payment/cancelMilestone.json", build_api_params({
234
+ :transactionid => params[:transaction_id]
235
+ }))
236
+
237
+ # Parse and return the response
238
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
239
+
240
+ end
241
+
242
+ # Request to release a milestone payment
243
+ #
244
+ # Valid parameters are:
245
+ # - transaction_id: the id of the milestone transaction to release
246
+ def request_release_milestone(*args)
247
+
248
+ params = extract_params(args)
249
+
250
+ # Execute the service call
251
+ result = api_get("/Payment/requestReleaseMilestone.json", build_api_params({
252
+ :transactionid => params[:transaction_id]
253
+ }))
254
+
255
+ # Parse and return the response
256
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
257
+
258
+ end
259
+
260
+ # Release a milestone payment
261
+ #
262
+ # Valid parameters are:
263
+ # - transaction_id: the id of the milestone transaction to release
264
+ # - full_name: the full name of the payer (signature)
265
+ def release_milestone(*args)
266
+
267
+ params = extract_params(args)
268
+
269
+ # Execute the service call
270
+ result = api_get("/Payment/releaseMilestone.json", build_api_params({
271
+ :transactionid => params[:transaction_id],
272
+ :fullname => params[:full_name]
273
+ }))
274
+
275
+ # Parse and return the response
276
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
277
+
278
+ end
279
+
280
+ # Prepare a transfer to validate it before actually transfering
281
+ #
282
+ # Valid parameters are:
283
+ # - project_id: the id of the project to transfer money for
284
+ # - amount: the amount of money to transfer
285
+ # - user_id: the id of the user to transfer money to
286
+ # - type: the type of transfer (partial, full or other)
287
+ def prepare_transfer(*args)
288
+
289
+ params = extract_params(args)
290
+
291
+ # Execute the service call
292
+ result = api_get("/Payment/prepareTransfer.json", build_api_params({
293
+ :projectid => params[:project_id],
294
+ :amount => params[:amount],
295
+ :touserid => params[:user_id],
296
+ :reasontype => params[:type]
297
+ }))
298
+
299
+ # Parse and return the response
300
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
301
+
302
+ end
303
+
120
304
  end
121
305
  end
122
306
  end
@@ -11,6 +11,46 @@ module Freelancer
11
11
 
12
12
  end
13
13
 
14
+ # Update one or more attributes for the current user. This method takes a
15
+ # User object, and this should in most cases have been populated by the
16
+ # account_details method before passed to the update_account_details
17
+ # method to ensure that no data gets lost.
18
+ def update_account_details(account)
19
+
20
+ # Prepare a map of update parameters
21
+ params = {}
22
+ params[:fullname] = account.name
23
+ params[:company_name] = account.company
24
+ params[:type_of_work] = account.type_of_work
25
+ params[:addressline1] = account.address.street_name
26
+ params[:addressline2] = account.address.street_name_2
27
+ params[:city] = account.address.city
28
+ params[:state] = account.address.state
29
+ params[:country] = account.address.country
30
+ params[:postalcode] = account.address.postal_code
31
+ params[:phone] = account.phone_number
32
+ params[:fax] = account.fax_number
33
+ params[:notificationformat] = account.notifications.notification_format
34
+ params[:emailnotificationstatus] = account.notifications.email
35
+ params[:receivenewsstatus] = account.notifications.news
36
+ params[:bidwonnotificationstatus] = account.notifications.bid_won
37
+ params[:bidplacednotificationstatus] = account.notifications.bid_placed
38
+ params[:newprivatemessagestatus] = account.notifications.new_private_message
39
+ params[:qualificationcsv] = account.qualifications.join(",")
40
+ params[:profiletext] = account.profile_text
41
+ params[:vision] = account.vision
42
+ params[:keywords] = account.keywords
43
+ params[:hourlyrate] = account.hourly_rate
44
+ params[:skills] = account.skills.join("\n")
45
+
46
+ # Execute the service call
47
+ result = api_get("/Profile/setProfileInfo.json", params)
48
+
49
+ # Parse and return the response
50
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
51
+
52
+ end
53
+
14
54
  # Retrieve profile information about a specific user
15
55
  #
16
56
  # Valid parameters are:
@@ -126,6 +126,26 @@ module Freelancer
126
126
 
127
127
  end
128
128
 
129
+ # Post a public message for a project
130
+ #
131
+ # Valid parameters are:
132
+ # - project_id: the id of the project to post the message to
133
+ # - message: the message to post
134
+ def post_public_project_message(*args)
135
+
136
+ params = extract_params(args)
137
+
138
+ # Execute the service call
139
+ result = api_get("/Project/postPublicMessage.json", build_api_params({
140
+ :projectid => params[:project_id],
141
+ :messagetext => params[:message]
142
+ }))
143
+
144
+ # Parse and return the response
145
+ ::Freelancer::Models::StatusConfirmation.parse(result, :shift => :"json-result")
146
+
147
+ end
148
+
129
149
  end
130
150
 
131
151
  end
@@ -75,7 +75,7 @@ module Freelancer
75
75
  return response.body
76
76
  end
77
77
 
78
- # Execute a GET-requset for the specified API method and return the raw
78
+ # Execute a GET-request for the specified API method and return the raw
79
79
  # result.
80
80
  def api_get_raw(method, options = {})
81
81
  response = access_token.get(to_uri(method, options))
@@ -83,14 +83,6 @@ module Freelancer
83
83
  response.body
84
84
  end
85
85
 
86
- # Execute a POST-request for the specified API method
87
- # TODO: Finish this method, it should probably return some JSON decoded
88
- # string.
89
- def api_post(method, body)
90
- response = access_token.post(method, body)
91
- response.body
92
- end
93
-
94
86
  private
95
87
 
96
88
  # Extract params from an array of arguments. Copied from ActiveSupport.
@@ -114,11 +106,29 @@ module Freelancer
114
106
 
115
107
  case response.code.to_i
116
108
  when 1..199
117
- raise "Response code #{response.code}: #{response}"
109
+ raise FreelancerRequestError.new("Got response code #{response.code} when executing API request")
118
110
  when 201..503
119
- raise "Response code: #{response.code}: #{response}"
111
+ raise FreelancerRequestError.new("Got response code #{response.code} when executing API request")
120
112
  end
121
-
113
+
114
+ # Attempt to convert the response to a JSON data structure
115
+ json = JSONMapper::Parser.parse(response.body)
116
+
117
+ # If we didn't get a proper response, raise an error
118
+ raise FreelancerResponseError.new("No or invalid response received when executing API request") if json.nil?
119
+
120
+ # If the JSON data has an error element as the only element,
121
+ # assume this request fails
122
+ if json.keys.size == 1 && json.keys.first == :errors
123
+
124
+ error_code = json[:errors][:error][:code]
125
+ error_message = json[:errors][:error][:msg]
126
+ error_description = json[:errors][:error][:longmsg]
127
+
128
+ raise FreelancerResponseError.new("#{error_message} - #{error_description} (code #{error_code})")
129
+
130
+ end
131
+
122
132
  end
123
133
 
124
134
  # Create a URI from the specified method and options
@@ -128,7 +138,7 @@ module Freelancer
128
138
  unless options.nil? || options.empty?
129
139
  uri.query = to_query(options)
130
140
  end
131
-
141
+
132
142
  return uri.to_s
133
143
 
134
144
  end