freelancer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +14 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +56 -0
  5. data/Rakefile +34 -0
  6. data/VERSION +1 -0
  7. data/freelancer.gemspec +299 -0
  8. data/init.rb +2 -0
  9. data/lib/freelancer.rb +59 -0
  10. data/lib/freelancer/api.rb +20 -0
  11. data/lib/freelancer/api/common.rb +58 -0
  12. data/lib/freelancer/api/employer.rb +56 -0
  13. data/lib/freelancer/api/freelancer.rb +36 -0
  14. data/lib/freelancer/api/job.rb +46 -0
  15. data/lib/freelancer/api/message.rb +89 -0
  16. data/lib/freelancer/api/notification.rb +25 -0
  17. data/lib/freelancer/api/payment.rb +123 -0
  18. data/lib/freelancer/api/profile.rb +30 -0
  19. data/lib/freelancer/api/project.rb +133 -0
  20. data/lib/freelancer/api/user.rb +86 -0
  21. data/lib/freelancer/client.rb +152 -0
  22. data/lib/freelancer/extensions/hash.rb +11 -0
  23. data/lib/freelancer/models/address.rb +46 -0
  24. data/lib/freelancer/models/balance.rb +22 -0
  25. data/lib/freelancer/models/bid.rb +41 -0
  26. data/lib/freelancer/models/config_version.rb +21 -0
  27. data/lib/freelancer/models/eligibility.rb +23 -0
  28. data/lib/freelancer/models/job.rb +33 -0
  29. data/lib/freelancer/models/job_category.rb +18 -0
  30. data/lib/freelancer/models/message.rb +32 -0
  31. data/lib/freelancer/models/milestone.rb +57 -0
  32. data/lib/freelancer/models/news.rb +15 -0
  33. data/lib/freelancer/models/notification.rb +15 -0
  34. data/lib/freelancer/models/notification_status.rb +45 -0
  35. data/lib/freelancer/models/project.rb +116 -0
  36. data/lib/freelancer/models/project_budget.rb +21 -0
  37. data/lib/freelancer/models/project_fee.rb +18 -0
  38. data/lib/freelancer/models/project_options.rb +34 -0
  39. data/lib/freelancer/models/rating.rb +21 -0
  40. data/lib/freelancer/models/review.rb +87 -0
  41. data/lib/freelancer/models/transaction.rb +39 -0
  42. data/lib/freelancer/models/user.rb +225 -0
  43. data/lib/freelancer/models/withdrawal.rb +51 -0
  44. data/lib/freelancer/models/withdrawal_fee.rb +39 -0
  45. data/lib/freelancer/support/json_mapper.rb +95 -0
  46. data/test/fixtures/common/get_config_version.json +1 -0
  47. data/test/fixtures/common/get_config_version.xml +5 -0
  48. data/test/fixtures/common/get_pending_feedback.json +1 -0
  49. data/test/fixtures/common/get_pending_feedback.xml +20 -0
  50. data/test/fixtures/common/get_terms.json +1 -0
  51. data/test/fixtures/common/get_terms.xml +4 -0
  52. data/test/fixtures/common/post_feedback.json +1 -0
  53. data/test/fixtures/common/post_feedback.xml +4 -0
  54. data/test/fixtures/common/post_reply_for_feedback.json +1 -0
  55. data/test/fixtures/common/post_reply_for_feedback.xml +4 -0
  56. data/test/fixtures/common/request_cancel_project.json +1 -0
  57. data/test/fixtures/common/request_cancel_project.xml +4 -0
  58. data/test/fixtures/common/request_withdraw_feedback.json +1 -0
  59. data/test/fixtures/common/request_withdraw_feedback.xml +4 -0
  60. data/test/fixtures/employer/choose_winner_for_project.json +1 -0
  61. data/test/fixtures/employer/choose_winner_for_project.xml +3 -0
  62. data/test/fixtures/employer/delete_draft_project.json +1 -0
  63. data/test/fixtures/employer/delete_draft_project.xml +4 -0
  64. data/test/fixtures/employer/eligible_for_trial_project.json +1 -0
  65. data/test/fixtures/employer/eligible_for_trial_project.xml +5 -0
  66. data/test/fixtures/employer/get_posted_project_list.json +1 -0
  67. data/test/fixtures/employer/get_posted_project_list.xml +38 -0
  68. data/test/fixtures/employer/invite_user_for_project.json +1 -0
  69. data/test/fixtures/employer/invite_user_for_project.xml +4 -0
  70. data/test/fixtures/employer/post_new_draft_project.json +1 -0
  71. data/test/fixtures/employer/post_new_draft_project.xml +5 -0
  72. data/test/fixtures/employer/post_new_project.json +1 -0
  73. data/test/fixtures/employer/post_new_project.xml +5 -0
  74. data/test/fixtures/employer/post_new_trial_project.json +1 -0
  75. data/test/fixtures/employer/post_new_trial_project.xml +5 -0
  76. data/test/fixtures/employer/publish_draft_project.json +1 -0
  77. data/test/fixtures/employer/publish_draft_project.xml +4 -0
  78. data/test/fixtures/employer/update_project_details.json +1 -0
  79. data/test/fixtures/employer/update_project_details.xml +4 -0
  80. data/test/fixtures/employer/upgrade_trial_project.json +1 -0
  81. data/test/fixtures/employer/upgrade_trial_project.xml +4 -0
  82. data/test/fixtures/freelancer/accept_bid_won.json +1 -0
  83. data/test/fixtures/freelancer/accept_bid_won.xml +4 -0
  84. data/test/fixtures/freelancer/get_project_list_for_placed_bids.json +1 -0
  85. data/test/fixtures/freelancer/get_project_list_for_placed_bids.xml +16 -0
  86. data/test/fixtures/freelancer/place_bid_on_project.json +1 -0
  87. data/test/fixtures/freelancer/place_bid_on_project.xml +4 -0
  88. data/test/fixtures/freelancer/retract_bid_from_project.json +1 -0
  89. data/test/fixtures/freelancer/retract_bid_from_project.xml +4 -0
  90. data/test/fixtures/job/get_category_job_list.json +1 -0
  91. data/test/fixtures/job/get_category_job_list.xml +34 -0
  92. data/test/fixtures/job/get_job_list.json +1 -0
  93. data/test/fixtures/job/get_job_list.xml +17 -0
  94. data/test/fixtures/job/get_my_job_list.json +1 -0
  95. data/test/fixtures/job/get_my_job_list.xml +11 -0
  96. data/test/fixtures/message/get_inbox_messages.json +1 -0
  97. data/test/fixtures/message/get_inbox_messages.xml +22 -0
  98. data/test/fixtures/message/get_sent_messages.json +1 -0
  99. data/test/fixtures/message/get_sent_messages.xml +22 -0
  100. data/test/fixtures/message/get_unread_count.json +1 -0
  101. data/test/fixtures/message/get_unread_count.xml +4 -0
  102. data/test/fixtures/message/load_message_thread.json +1 -0
  103. data/test/fixtures/message/load_message_thread.xml +54 -0
  104. data/test/fixtures/message/mark_message_as_read.json +1 -0
  105. data/test/fixtures/message/mark_message_as_read.xml +4 -0
  106. data/test/fixtures/message/send_message.json +1 -0
  107. data/test/fixtures/message/send_message.xml +4 -0
  108. data/test/fixtures/notification/get_news.json +1 -0
  109. data/test/fixtures/notification/get_news.xml +14 -0
  110. data/test/fixtures/notification/get_notification.json +1 -0
  111. data/test/fixtures/notification/get_notification.xml +10 -0
  112. data/test/fixtures/payment/cancel_milestone.json +1 -0
  113. data/test/fixtures/payment/cancel_milestone.xml +4 -0
  114. data/test/fixtures/payment/create_milestone_payment.json +1 -0
  115. data/test/fixtures/payment/create_milestone_payment.xml +4 -0
  116. data/test/fixtures/payment/get_account_balance_status.json +1 -0
  117. data/test/fixtures/payment/get_account_balance_status.xml +12 -0
  118. data/test/fixtures/payment/get_account_milestone_list.json +1 -0
  119. data/test/fixtures/payment/get_account_milestone_list.xml +30 -0
  120. data/test/fixtures/payment/get_account_transaction_list.json +1 -0
  121. data/test/fixtures/payment/get_account_transaction_list.xml +57 -0
  122. data/test/fixtures/payment/get_account_withdrawal_list.json +1 -0
  123. data/test/fixtures/payment/get_account_withdrawal_list.xml +42 -0
  124. data/test/fixtures/payment/get_balance.json +1 -0
  125. data/test/fixtures/payment/get_balance.xml +4 -0
  126. data/test/fixtures/payment/get_project_list_for_transfer.json +1 -0
  127. data/test/fixtures/payment/get_project_list_for_transfer.xml +52 -0
  128. data/test/fixtures/payment/get_withdrawal_fees.json +1 -0
  129. data/test/fixtures/payment/get_withdrawal_fees.xml +41 -0
  130. data/test/fixtures/payment/prepare_transfer.json +1 -0
  131. data/test/fixtures/payment/prepare_transfer.xml +4 -0
  132. data/test/fixtures/payment/release_milestone.json +1 -0
  133. data/test/fixtures/payment/release_milestone.xml +4 -0
  134. data/test/fixtures/payment/request_cancel_withdrawal.json +1 -0
  135. data/test/fixtures/payment/request_cancel_withdrawal.xml +4 -0
  136. data/test/fixtures/payment/request_release_milestone.json +1 -0
  137. data/test/fixtures/payment/request_release_milestone.xml +4 -0
  138. data/test/fixtures/payment/request_withdrawal.json +1 -0
  139. data/test/fixtures/payment/request_withdrawal.xml +6 -0
  140. data/test/fixtures/payment/transfer_money.json +1 -0
  141. data/test/fixtures/payment/transfer_money.xml +4 -0
  142. data/test/fixtures/profile/get_account_details.json +1 -0
  143. data/test/fixtures/profile/get_account_details.xml +71 -0
  144. data/test/fixtures/profile/get_profile_info.json +1 -0
  145. data/test/fixtures/profile/get_profile_info.xml +53 -0
  146. data/test/fixtures/profile/set_profile_info.json +1 -0
  147. data/test/fixtures/profile/set_profile_info.xml +4 -0
  148. data/test/fixtures/project/get_bids_details.json +1 -0
  149. data/test/fixtures/project/get_bids_details.xml +19 -0
  150. data/test/fixtures/project/get_project_budget_config.json +1 -0
  151. data/test/fixtures/project/get_project_budget_config.xml +42 -0
  152. data/test/fixtures/project/get_project_details.json +1 -0
  153. data/test/fixtures/project/get_project_details.xml +78 -0
  154. data/test/fixtures/project/get_project_fees.json +1 -0
  155. data/test/fixtures/project/get_project_fees.xml +31 -0
  156. data/test/fixtures/project/get_public_messages.json +1 -0
  157. data/test/fixtures/project/get_public_messages.xml +27 -0
  158. data/test/fixtures/project/get_sent_messages.xml +22 -0
  159. data/test/fixtures/project/get_unread_count.xml +4 -0
  160. data/test/fixtures/project/load_message_thread.xml +54 -0
  161. data/test/fixtures/project/mark_message_as_read.xml +4 -0
  162. data/test/fixtures/project/post_public_message.json +1 -0
  163. data/test/fixtures/project/post_public_message.xml +4 -0
  164. data/test/fixtures/project/search_projects.json +1 -0
  165. data/test/fixtures/project/search_projects.xml +37 -0
  166. data/test/fixtures/project/send_message.xml +4 -0
  167. data/test/fixtures/user/get_user_details.json +1 -0
  168. data/test/fixtures/user/get_user_details.xml +32 -0
  169. data/test/fixtures/user/get_user_feedback.json +1 -0
  170. data/test/fixtures/user/get_user_feedback.xml +58 -0
  171. data/test/fixtures/user/get_users_by_search.json +1 -0
  172. data/test/fixtures/user/get_users_by_search.xml +26 -0
  173. data/test/freelancer/api/common_api_test.rb +82 -0
  174. data/test/freelancer/api/employer_api_test.rb +105 -0
  175. data/test/freelancer/api/freelancer_api_test.rb +72 -0
  176. data/test/freelancer/api/job_api_test.rb +76 -0
  177. data/test/freelancer/api/message_api_test.rb +144 -0
  178. data/test/freelancer/api/notification_api_test.rb +56 -0
  179. data/test/freelancer/api/payment_api_test.rb +225 -0
  180. data/test/freelancer/api/profile_api_test.rb +54 -0
  181. data/test/freelancer/api/project_api_test.rb +229 -0
  182. data/test/freelancer/api/user_api_test.rb +153 -0
  183. data/test/freelancer/client_test.rb +5 -0
  184. data/test/freelancer/models/balance_test.rb +24 -0
  185. data/test/freelancer/models/bid_test.rb +25 -0
  186. data/test/freelancer/models/config_version.rb +14 -0
  187. data/test/freelancer/models/eligibility_test.rb +14 -0
  188. data/test/freelancer/models/job_category_test.rb +16 -0
  189. data/test/freelancer/models/job_test.rb +19 -0
  190. data/test/freelancer/models/message_test.rb +42 -0
  191. data/test/freelancer/models/milestone_test.rb +21 -0
  192. data/test/freelancer/models/news_test.rb +15 -0
  193. data/test/freelancer/models/notification_test.rb +15 -0
  194. data/test/freelancer/models/project_budget_test.rb +18 -0
  195. data/test/freelancer/models/project_fee_test.rb +17 -0
  196. data/test/freelancer/models/project_test.rb +97 -0
  197. data/test/freelancer/models/review_test.rb +36 -0
  198. data/test/freelancer/models/transaction_test.rb +29 -0
  199. data/test/freelancer/models/user_test.rb +94 -0
  200. data/test/freelancer/models/withdrawal_fee_test.rb +19 -0
  201. data/test/freelancer/models/withdrawal_test.rb +20 -0
  202. data/test/freelancer/oauth_test.rb +112 -0
  203. data/test/freelancer_test.rb +1 -0
  204. data/test/test_helper.rb +42 -0
  205. metadata +427 -0
@@ -0,0 +1,20 @@
1
+ module Freelancer
2
+ module API
3
+
4
+ # Returns the list of registered APIs
5
+ def apis
6
+ @apis ||= []
7
+ end
8
+
9
+ # Include the specified API
10
+ def api(api)
11
+
12
+ extend api::ClassMethods if api.const_defined?(:ClassMethods)
13
+ include api::InstanceMethods if api.const_defined?(:InstanceMethods)
14
+
15
+ apis << api
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,58 @@
1
+ module Freelancer
2
+ module API
3
+ module Common
4
+ module InstanceMethods
5
+
6
+ # Get a list of projects that are pending feedback
7
+ #
8
+ # Valid parameters are:
9
+ # - type: the type of projects to list ("P" or "B" (default))
10
+ def pending_feedback(*args)
11
+
12
+ params = extract_params(args)
13
+
14
+ # Execute the service call
15
+ result = api_get("/Common/getPendingFeedback.json", build_api_params({
16
+ :type => params[:type]
17
+ }))
18
+
19
+ # Parse and return the response
20
+ ::Freelancer::Models::Project.parse_collection(result, :shift => [ :"json-result", :items ])
21
+
22
+ end
23
+
24
+ # Get the configuration version of a specific service function
25
+ #
26
+ # Valid parameters are:
27
+ # - function: the function to look up config version for
28
+ def config_version(*args)
29
+
30
+ params = extract_params(args)
31
+
32
+ # Execute the service call
33
+ result = api_get("/Common/getConfigVersion.json", build_api_params({
34
+ :function => params[:function]
35
+ }))
36
+
37
+ # Parse and return the response
38
+ ::Freelancer::Models::ConfigVersion.parse(result, :shift => :"json-result")
39
+
40
+ end
41
+
42
+ # Returns the current Terms and Conditions from the site
43
+ def terms
44
+
45
+ result = api_get("/Common/getTerms.json")
46
+ json = JSONMapper::Parser.parse(result)
47
+
48
+ if !json.nil? && json.key?(:"json-result")
49
+ return json[:"json-result"][:terms]
50
+ end
51
+ return nil
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,56 @@
1
+ module Freelancer
2
+ module API
3
+ module Employer
4
+ module InstanceMethods
5
+
6
+ # Retrieve a list of projects posted by a user. By default, this
7
+ # retrieves the projects posted by the currently authenticated user.
8
+ #
9
+ # Valid parameters are:
10
+ # - status: the status value to filter projects by (defaults to 2 (open and frozen))
11
+ # - user_id: the id of the user to list projects for (defaults to current user)
12
+ # - project_id: the project id to filter projects by
13
+ # - type: the project type to use ('active', 'trial' and 'draft' - defaults to 'active')
14
+ # - count: the number of results to return (defaults to 50)
15
+ # - page: the page to retrieve (defaults to 0)
16
+ def posted_projects(*args)
17
+
18
+ params = extract_params(args)
19
+
20
+ # Use a blank type value if type is set to 'active'
21
+ params[:type] = nil if params[:type] == "active"
22
+
23
+ # Execute the service call
24
+ result = api_get("/Employer/getPostedProjectList.json", build_api_params({
25
+ :status => params[:status],
26
+ :userid => params[:user_id],
27
+ :projectid => params[:project_id],
28
+ :projectoption => params[:type],
29
+ :count => params[:count],
30
+ :page => params[:page]
31
+ }))
32
+
33
+ # Parse and return the response
34
+ ::Freelancer::Models::Project.parse_collection(result, :shift => [ :"json-result", :items ])
35
+
36
+ end
37
+
38
+ # Check if the current user is eligible to post trial projects
39
+ def eligible_for_trial_project
40
+
41
+ result = api_get("/Employer/eligibleForTrialProject.json")
42
+ ::Freelancer::Models::Eligibility.parse(result, :shift => :"json-result")
43
+
44
+ end
45
+
46
+ # Returns true if the current user is eligible to post trial projects,
47
+ # false otherwise
48
+ def eligible_for_trial_project?
49
+ eligibility = eligible_for_trial_project
50
+ !eligibility.nil? && eligibility.eligible?
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,36 @@
1
+ module Freelancer
2
+ module API
3
+ module Freelancer
4
+ module InstanceMethods
5
+
6
+ # Get a list of all projects where the specified user have placed a bid.
7
+ # If no user id is specified, the current user is used.
8
+ #
9
+ # Valid parameters are:
10
+ # - status: the project status to filter the results by (defaults to 2 - open and frozen)
11
+ # - user_id: the id of the user to retrieve projects for
12
+ # - project_id: the project id to filter the results by
13
+ # - count: the number of results to return (defaults to 50)
14
+ # - page: the page to retrieve (defaults to 0)
15
+ def bid_projects(*args)
16
+
17
+ params = extract_params(args)
18
+
19
+ # Execute the service call
20
+ result = api_get("/Freelancer/getProjectListForPlacedBids.json", build_api_params({
21
+ :status => params[:status],
22
+ :userid => params[:user_id],
23
+ :projectid => params[:project_id],
24
+ :count => params[:count],
25
+ :page => params[:page]
26
+ }))
27
+
28
+ # Parse and return the response
29
+ ::Freelancer::Models::Project.parse_collection(result, :shift => [ :"json-result", :items ])
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,46 @@
1
+ module Freelancer
2
+ module API
3
+ module Job
4
+ module InstanceMethods
5
+
6
+ # Retrieve a list of available jobs
7
+ def jobs
8
+
9
+ result = api_get("/Job/getJobList.json")
10
+ ::Freelancer::Models::Job.parse_collection(result, :shift => [ :"json-result", :items ])
11
+
12
+ end
13
+
14
+ # Retrieve a list of available job categories
15
+ def job_categories
16
+
17
+ result = api_get("/Job/getCategoryJobList.json")
18
+ ::Freelancer::Models::JobCategory.parse_collection(result, :shift => [ :"json-result", :items, :category ])
19
+
20
+ end
21
+
22
+ # Retrieve a list of the current users jobs
23
+ def my_jobs
24
+
25
+ result = api_get("/Job/getMyJobList.json")
26
+
27
+ # We need to hack this to make the job id a sub element of the
28
+ # job node to make the mapping work properly.
29
+ json_result = JSONMapper::Parser.parse(result)
30
+ jobs = []
31
+ unless json_result.nil?
32
+
33
+ json_result[:"json-result"][:items][:job].each do |item|
34
+ jobs << { :id => item }
35
+ end
36
+
37
+ end
38
+
39
+ ::Freelancer::Models::Job.parse_json_collection(jobs)
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,89 @@
1
+ module Freelancer
2
+ module API
3
+ module Message
4
+ module InstanceMethods
5
+
6
+ # Return the private messages sent to the current user
7
+ #
8
+ # Valid parameters are:
9
+ # - project_id: the project id to filter messages by
10
+ # - count: the number of results to return (defaults to 50)
11
+ # - page: the page to retrieve (defaults to 0)
12
+ def messages(*args)
13
+
14
+ params = extract_params(args)
15
+
16
+ # Execute the service call
17
+ result = api_get("/Message/getInboxMessages.json", build_api_params({
18
+ :projectid => params[:project_id],
19
+ :count => params[:count],
20
+ :page => params[:page]
21
+ }))
22
+
23
+ # Parse and return the response
24
+ ::Freelancer::Models::Message.parse_collection(result, :shift => [ :"json-result", :items ])
25
+
26
+ end
27
+
28
+ # Retrieve the messages the current user has sent to other users
29
+ #
30
+ # Valid parameters are:
31
+ # - count: the number of results to return (defaults to 50)
32
+ # - page: the page to retrieve (defaults to 0)
33
+ def sent_messages(*args)
34
+
35
+ params = extract_params(args)
36
+
37
+ # Execute the service call
38
+ result = api_get("/Message/getSentMessages.json", build_api_params({
39
+ :count => params[:count],
40
+ :page => params[:page]
41
+ }))
42
+
43
+ # Parse and return the response
44
+ ::Freelancer::Models::Message.parse_collection(result, :shift => [ :"json-result", :items ])
45
+
46
+ end
47
+
48
+ # Retrieve the number of unread messages the current user has available
49
+ def unread_message_count
50
+
51
+ result = api_get("/Message/getUnreadCount.json")
52
+ json = JSONMapper::Parser.parse(result)
53
+
54
+ if !json.nil? && json.key?(:"json-result")
55
+ return json[:"json-result"][:unreadcount].to_i
56
+ end
57
+ return nil
58
+
59
+ end
60
+
61
+ # Retrieve the full thread of private messages sent between two users
62
+ # within a project.
63
+ #
64
+ # Valid parameters are:
65
+ # - project_id: the id of the project to load messages for
66
+ # - between_user_id: the id of the receiving user to load the thread for
67
+ # - count: the number of messages to retrieve (defaults to 50)
68
+ # - page: the page number to retrieve (defaults to 0)
69
+ def message_thread(*args)
70
+
71
+ params = extract_params(args)
72
+
73
+ # Execute the service call
74
+ result = api_get("/Message/loadMessageThread.json", build_api_params({
75
+ :projectid => params[:project_id],
76
+ :betweenuserid => params[:between_user_id],
77
+ :count => params[:count],
78
+ :page => params[:page]
79
+ }))
80
+
81
+ # Parse and return the response
82
+ ::Freelancer::Models::Message.parse_collection(result, :shift => [ :"json-result", :items, :message ])
83
+
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,25 @@
1
+ module Freelancer
2
+ module API
3
+ module Notification
4
+ module InstanceMethods
5
+
6
+ # Get a list of available alerts for the current user
7
+ def notifications
8
+
9
+ result = api_get("/Notification/getNotification.json")
10
+ ::Freelancer::Models::Notification.parse_collection(result, :shift => [ :"json-result", :items, :notification ])
11
+
12
+ end
13
+
14
+ # Return a list of available news items
15
+ def news
16
+
17
+ result = api_get("/Notification/getNews.json")
18
+ ::Freelancer::Models::News.parse_collection(result, :shift => [ :"json-result", :items ])
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,123 @@
1
+ module Freelancer
2
+ module API
3
+ module Payment
4
+ module InstanceMethods
5
+
6
+ # Retrieve the current users balance and the details of the last
7
+ # transaction.
8
+ def account_balance
9
+
10
+ result = api_get("/Payment/getAccountBalanceStatus.json")
11
+ ::Freelancer::Models::Balance.parse(result, :shift => :"json-result")
12
+
13
+ end
14
+
15
+ # Retrieve a list of transactions for the current user
16
+ #
17
+ # Valid parameters are:
18
+ # - from: the from date/time to search by
19
+ # - to: the to date/time to search by
20
+ # - count: the number of results to return (defaults to 50)
21
+ # - page: the page to retrieve (defaults to 0)
22
+ def transactions(*args)
23
+
24
+ params = extract_params(args)
25
+
26
+ # If we have a from or to date, convert it to a string
27
+ if params.key?(:from) && params[:from].is_a?(Date)
28
+ params[:from] = params[:from].strftime("%Y-%m-%d %H:%M:%S")
29
+ end
30
+ if params.key?(:to) && params[:to].is_a?(Date)
31
+ params[:to] = params[:to].strftime("%Y-%m-%d %H:%M:%S")
32
+ end
33
+
34
+ # Execute the service call
35
+ result = api_get("/Payment/getAccountTransactionList.json", build_api_params({
36
+ :datefrom => params[:from],
37
+ :dateto => params[:to],
38
+ :count => params[:count],
39
+ :page => params[:page]
40
+ }))
41
+
42
+ # Parse and return the response
43
+ ::Freelancer::Models::Transaction.parse_collection(result, :shift => [ :"json-result", :items ])
44
+
45
+ end
46
+
47
+ # Retrieve a list of milestones for the current user
48
+ #
49
+ # Valid parameters are:
50
+ # - type: the type of milestone (Incoming (default) or Outgoing)
51
+ # - count: the number of results to return (defaults to 50)
52
+ # - page: the page to retrieve (defaults to 0)
53
+ def account_milestones(*args)
54
+
55
+ params = extract_params(args)
56
+
57
+ # Execute the service call
58
+ result = api_get("/Payment/getAccountMilestoneList.json", build_api_params({
59
+ :type => params[:type],
60
+ :count => params[:count],
61
+ :page => params[:page]
62
+ }))
63
+
64
+ # Parse and return the response
65
+ ::Freelancer::Models::Milestone.parse_collection(result, :shift => [ :"json-result", :items ])
66
+
67
+ end
68
+
69
+ # Retrieve a list of withdrawals for the current user
70
+ #
71
+ # Valid parameters are:
72
+ # - type: the type of withdrawal (Incoming (default) or Outgoing)
73
+ # - count: the number of results to return (defaults to 50)
74
+ # - page: the page to retrieve (defaults to 0)
75
+ def account_withdrawals(*args)
76
+
77
+ params = extract_params(args)
78
+
79
+ # Execute the service call
80
+ result = api_get("/Payment/getAccountWithdrawalList.json", build_api_params({
81
+ :type => params[:type],
82
+ :count => params[:count],
83
+ :page => params[:page]
84
+ }))
85
+
86
+ # Parse and return the response
87
+ ::Freelancer::Models::Withdrawal.parse_collection(result, :shift => [ :"json-result", :items ])
88
+
89
+ end
90
+
91
+ # Retrieve the balance for the current user
92
+ def balance
93
+
94
+ result = api_get("/Payment/getBalance.json")
95
+ json = JSONMapper::Parser.parse(result)
96
+
97
+ if !json.nil? && json.key?(:"json-result")
98
+ return json[:"json-result"][:balance].to_f
99
+ end
100
+ return nil
101
+
102
+ end
103
+
104
+ # Retrieve a list of available withdrawal fees
105
+ def withdrawal_fees
106
+
107
+ result = api_get("/Payment/getWithdrawalFees.json")
108
+ ::Freelancer::Models::WithdrawalFee.parse_collection(result, :shift => [ :"json-result", :items, :fee ])
109
+
110
+ end
111
+
112
+ # Retrieve a list of projects that's available for transfers
113
+ def projects_for_transfer
114
+
115
+ result = api_get("/Payment/getProjectListForTransfer.json")
116
+ ::Freelancer::Models::Project.parse_collection(result, :shift => [ :"json-result", :items, :project ])
117
+
118
+ end
119
+
120
+ end
121
+ end
122
+ end
123
+ end