freelancer 0.1.0

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.
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,72 @@
1
+ require "test_helper"
2
+
3
+ class FreelancerApiTest < Test::Unit::TestCase
4
+
5
+ context "freelancer api" do
6
+
7
+ setup do
8
+ @freelancer = Freelancer::Client.new("consumer_token", "consumer_secret")
9
+ consumer = OAuth::Consumer.new("consumer_token", "consumer_secret", { :site => "http://api.sandbox.freelancer.com" })
10
+ @freelancer.stubs(:consumer).returns(consumer)
11
+ @freelancer.authorize_from_access("access_token", "access_secret")
12
+ end
13
+
14
+ context "project list for placed bids" do
15
+
16
+ should "be able to retrieve" do
17
+
18
+ @freelancer.expects(:api_get).with("/Freelancer/getProjectListForPlacedBids.json", {})
19
+ @freelancer.bid_projects
20
+
21
+ end
22
+
23
+ should "be able to retrieve by status" do
24
+
25
+ @freelancer.expects(:api_get).with("/Freelancer/getProjectListForPlacedBids.json", { :status => 1 })
26
+ @freelancer.bid_projects(:status => 1)
27
+
28
+ end
29
+
30
+ should "be able to retrieve by user id" do
31
+
32
+ @freelancer.expects(:api_get).with("/Freelancer/getProjectListForPlacedBids.json", { :userid => 1 })
33
+ @freelancer.bid_projects(:user_id => 1)
34
+
35
+ end
36
+
37
+ should "be able to retrieve by project id" do
38
+
39
+ @freelancer.expects(:api_get).with("/Freelancer/getProjectListForPlacedBids.json", { :projectid => 1 })
40
+ @freelancer.bid_projects(:project_id => 1)
41
+
42
+ end
43
+
44
+ should "be able to change result count" do
45
+
46
+ @freelancer.expects(:api_get).with("/Freelancer/getProjectListForPlacedBids.json", { :count => 10 })
47
+ @freelancer.bid_projects(:count => 10)
48
+
49
+ end
50
+
51
+ should "be able to change result page" do
52
+
53
+ @freelancer.expects(:api_get).with("/Freelancer/getProjectListForPlacedBids.json", { :page => 2 })
54
+ @freelancer.bid_projects(:page => 2)
55
+
56
+ end
57
+
58
+ should "parse response into a collection of projects" do
59
+
60
+ stub_api_get("/Freelancer/getProjectListForPlacedBids.json", "freelancer/get_project_list_for_placed_bids.json")
61
+
62
+ projects = @freelancer.bid_projects
63
+ projects.size.should == 1
64
+ projects.first.id.should == 191
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,76 @@
1
+ require "test_helper"
2
+
3
+ class JobApiTest < Test::Unit::TestCase
4
+
5
+ context "job api" do
6
+
7
+ setup do
8
+ @freelancer = Freelancer::Client.new("consumer_token", "consumer_secret")
9
+ consumer = OAuth::Consumer.new("consumer_token", "consumer_secret", { :site => "http://api.sandbox.freelancer.com" })
10
+ @freelancer.stubs(:consumer).returns(consumer)
11
+ @freelancer.authorize_from_access("access_token", "access_secret")
12
+ end
13
+
14
+ context "job list" do
15
+
16
+ should "be able to retrieve" do
17
+
18
+ @freelancer.expects(:api_get).with("/Job/getJobList.json")
19
+ @freelancer.jobs
20
+
21
+ end
22
+
23
+ should "parse response into a collection of jobs" do
24
+
25
+ stub_api_get("/Job/getJobList.json", "job/get_job_list.json")
26
+ jobs = @freelancer.jobs
27
+ jobs.size.should == 325
28
+ jobs.first.id == 15
29
+
30
+ end
31
+
32
+ end
33
+
34
+ context "job category list" do
35
+
36
+ should "be able to retrieve" do
37
+
38
+ @freelancer.expects(:api_get).with("/Job/getCategoryJobList.json")
39
+ @freelancer.job_categories
40
+
41
+ end
42
+
43
+ should "parse response into a collection of categories" do
44
+
45
+ stub_api_get("/Job/getCategoryJobList.json", "job/get_category_job_list.json")
46
+ categories = @freelancer.job_categories
47
+ categories.size.should == 10
48
+ categories.first.id.should == 1
49
+
50
+ end
51
+
52
+ end
53
+
54
+ context "my job list" do
55
+
56
+ should "be able to retrieve" do
57
+
58
+ @freelancer.expects(:api_get).with("/Job/getMyJobList.json")
59
+ @freelancer.my_jobs
60
+
61
+ end
62
+
63
+ should "parse response into a collection of jobs" do
64
+
65
+ stub_api_get("/Job/getMyJobList.json", "job/get_my_job_list.json")
66
+ jobs = @freelancer.my_jobs
67
+ jobs.size.should == 4
68
+ jobs.first.id.should == 3
69
+
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,144 @@
1
+ require "test_helper"
2
+
3
+ class MessageApiTest < Test::Unit::TestCase
4
+
5
+ context "message api" do
6
+
7
+ setup do
8
+ @freelancer = Freelancer::Client.new("consumer_token", "consumer_secret")
9
+ consumer = OAuth::Consumer.new("consumer_token", "consumer_secret", { :site => "http://api.sandbox.freelancer.com" })
10
+ @freelancer.stubs(:consumer).returns(consumer)
11
+ @freelancer.authorize_from_access("access_token", "access_secret")
12
+ end
13
+
14
+ context "inbox messages" do
15
+
16
+ should "be able to list" do
17
+
18
+ @freelancer.expects(:api_get).with("/Message/getInboxMessages.json", {})
19
+ @freelancer.messages
20
+
21
+ end
22
+
23
+ should "be able to list by project id" do
24
+
25
+ @freelancer.expects(:api_get).with("/Message/getInboxMessages.json", { :projectid => 1 })
26
+ @freelancer.messages(:project_id => 1)
27
+
28
+ end
29
+
30
+ should "be able to change result count" do
31
+
32
+ @freelancer.expects(:api_get).with("/Message/getInboxMessages.json", { :count => 20 })
33
+ @freelancer.messages(:count => 20)
34
+
35
+ end
36
+
37
+ should "be able to change result page" do
38
+
39
+ @freelancer.expects(:api_get).with("/Message/getInboxMessages.json", { :page => 2 })
40
+ @freelancer.messages(:page => 2)
41
+
42
+ end
43
+
44
+ should "parse response into a collection of messages" do
45
+
46
+ stub_api_get("/Message/getInboxMessages.json", "message/get_inbox_messages.json")
47
+ messages = @freelancer.messages
48
+ messages.size.should == 1
49
+ messages.first.id.should == 203
50
+
51
+ end
52
+
53
+ end
54
+
55
+ context "sent messages" do
56
+
57
+ should "be able to list" do
58
+
59
+ @freelancer.expects(:api_get).with("/Message/getSentMessages.json", {})
60
+ @freelancer.sent_messages
61
+
62
+ end
63
+
64
+ should "be able to change result count" do
65
+
66
+ @freelancer.expects(:api_get).with("/Message/getSentMessages.json", { :count => 20 })
67
+ @freelancer.sent_messages(:count => 20)
68
+
69
+ end
70
+
71
+ should "be able to change result page" do
72
+
73
+ @freelancer.expects(:api_get).with("/Message/getSentMessages.json", { :page => 2 })
74
+ @freelancer.sent_messages(:page => 2)
75
+
76
+ end
77
+
78
+ should "parse response into a collection of messages" do
79
+
80
+ stub_api_get("/Message/getSentMessages.json", "message/get_sent_messages.json")
81
+ messages = @freelancer.sent_messages
82
+ messages.size.should == 2
83
+ messages.first.project_id.should == 281
84
+
85
+ end
86
+
87
+ end
88
+
89
+ context "unread count" do
90
+
91
+ should "be able to retrieve" do
92
+
93
+ @freelancer.expects(:api_get).with("/Message/getUnreadCount.json")
94
+ @freelancer.unread_message_count
95
+
96
+ end
97
+
98
+ should "return a number" do
99
+
100
+ stub_api_get("/Message/getUnreadCount.json", "message/get_unread_count.json")
101
+ count = @freelancer.unread_message_count
102
+ count.should == 1
103
+
104
+ end
105
+
106
+ end
107
+
108
+ context "message thread" do
109
+
110
+ should "be able to retrieve" do
111
+
112
+ @freelancer.expects(:api_get).with("/Message/loadMessageThread.json", { :projectid => 1, :betweenuserid => 1 })
113
+ @freelancer.message_thread(:project_id => 1, :between_user_id => 1)
114
+
115
+ end
116
+
117
+ should "be able to change result count" do
118
+
119
+ @freelancer.expects(:api_get).with("/Message/loadMessageThread.json", { :count => 20 })
120
+ @freelancer.message_thread(:count => 20)
121
+
122
+ end
123
+
124
+ should "be able to change result page" do
125
+
126
+ @freelancer.expects(:api_get).with("/Message/loadMessageThread.json", { :page => 2 })
127
+ @freelancer.message_thread(:page => 2)
128
+
129
+ end
130
+
131
+ should "parse response into a collection of messages" do
132
+
133
+ stub_api_get("/Message/loadMessageThread.json", "message/load_message_thread.json")
134
+ messages = @freelancer.message_thread
135
+ messages.size.should == 3
136
+ messages.first.id.should == 203
137
+
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+ end
@@ -0,0 +1,56 @@
1
+ require "test_helper"
2
+
3
+ class NotificationApiTest < Test::Unit::TestCase
4
+
5
+ context "notification api" do
6
+
7
+ setup do
8
+ @freelancer = Freelancer::Client.new("consumer_token", "consumer_secret")
9
+ consumer = OAuth::Consumer.new("consumer_token", "consumer_secret", { :site => "http://api.sandbox.freelancer.com" })
10
+ @freelancer.stubs(:consumer).returns(consumer)
11
+ @freelancer.authorize_from_access("access_token", "access_secret")
12
+ end
13
+
14
+ context "notification list" do
15
+
16
+ should "be able to retrieve" do
17
+
18
+ @freelancer.expects(:api_get).with("/Notification/getNotification.json")
19
+ @freelancer.notifications
20
+
21
+ end
22
+
23
+ should "parse response into a collection of notifications" do
24
+
25
+ stub_api_get("/Notification/getNotification.json", "notification/get_notification.json")
26
+ notifications = @freelancer.notifications
27
+ notifications.size.should == 1
28
+ notifications.first.description.should == "Test notification"
29
+
30
+ end
31
+
32
+ end
33
+
34
+ context "news list" do
35
+
36
+ should "be able to retrieve" do
37
+
38
+ @freelancer.expects(:api_get).with("/Notification/getNews.json")
39
+ @freelancer.news
40
+
41
+ end
42
+
43
+ should "parse response into a collection of news" do
44
+
45
+ stub_api_get("/Notification/getNews.json", "notification/get_news.json")
46
+ news = @freelancer.news
47
+ news.size.should == 8
48
+ news.first.id.should == 177
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,225 @@
1
+ require "test_helper"
2
+
3
+ class PaymentApiTest < Test::Unit::TestCase
4
+
5
+ context "payment api" do
6
+
7
+ setup do
8
+ @freelancer = Freelancer::Client.new("consumer_token", "consumer_secret")
9
+ consumer = OAuth::Consumer.new("consumer_token", "consumer_secret", { :site => "http://api.sandbox.freelancer.com" })
10
+ @freelancer.stubs(:consumer).returns(consumer)
11
+ @freelancer.authorize_from_access("access_token", "access_secret")
12
+ end
13
+
14
+ context "account balance status" do
15
+
16
+ should "be able to retrieve" do
17
+
18
+ @freelancer.expects(:api_get).with("/Payment/getAccountBalanceStatus.json")
19
+ @freelancer.account_balance
20
+
21
+ end
22
+
23
+ should "parse response into balance model" do
24
+
25
+ stub_api_get("/Payment/getAccountBalanceStatus.json", "payment/get_account_balance_status.json")
26
+ balance = @freelancer.account_balance
27
+ balance.amount.should == 9717.55
28
+
29
+ end
30
+
31
+ end
32
+
33
+ context "account transactions" do
34
+
35
+ should "be able to retrieve" do
36
+
37
+ @freelancer.expects(:api_get).with("/Payment/getAccountTransactionList.json", {})
38
+ @freelancer.transactions
39
+
40
+ end
41
+
42
+ should "be able to retrieve by from date" do
43
+
44
+ @freelancer.expects(:api_get).with("/Payment/getAccountTransactionList.json", { :datefrom => "2010-08-09 17:51:00" })
45
+ @freelancer.transactions(:from => DateTime.parse("2010-08-09 17:51:00"))
46
+
47
+ end
48
+
49
+ should "be able to retrieve by to date" do
50
+
51
+ @freelancer.expects(:api_get).with("/Payment/getAccountTransactionList.json", { :dateto => "2010-08-09 17:51:00" })
52
+ @freelancer.transactions(:to => DateTime.parse("2010-08-09 17:51:00"))
53
+
54
+ end
55
+
56
+ should "be able to change result count" do
57
+
58
+ @freelancer.expects(:api_get).with("/Payment/getAccountTransactionList.json", { :count => 10 })
59
+ @freelancer.transactions(:count => 10)
60
+
61
+ end
62
+
63
+ should "be able to change result page" do
64
+
65
+ @freelancer.expects(:api_get).with("/Payment/getAccountTransactionList.json", { :page => 2 })
66
+ @freelancer.transactions(:page => 2)
67
+
68
+ end
69
+
70
+ should "parse response into a collection of transactions" do
71
+
72
+ stub_api_get("/Payment/getAccountTransactionList.json", "payment/get_account_transaction_list.json")
73
+ transactions = @freelancer.transactions
74
+ transactions.size.should == 8
75
+ transactions.first.balance.should == 250
76
+
77
+ end
78
+
79
+ end
80
+
81
+ context "account milestone list" do
82
+
83
+ should "be able to retrieve" do
84
+
85
+ @freelancer.expects(:api_get).with("/Payment/getAccountMilestoneList.json", {})
86
+ @freelancer.account_milestones
87
+
88
+ end
89
+
90
+ should "be able to retrieve by type" do
91
+
92
+ @freelancer.expects(:api_get).with("/Payment/getAccountMilestoneList.json", { :type => "Outgoing" })
93
+ @freelancer.account_milestones(:type => "Outgoing")
94
+
95
+ end
96
+
97
+ should "be able to change result count" do
98
+
99
+ @freelancer.expects(:api_get).with("/Payment/getAccountMilestoneList.json", { :count => 20 })
100
+ @freelancer.account_milestones(:count => 20)
101
+
102
+ end
103
+
104
+ should "be able to change result page" do
105
+
106
+ @freelancer.expects(:api_get).with("/Payment/getAccountMilestoneList.json", { :page => 2 })
107
+ @freelancer.account_milestones(:page => 2)
108
+
109
+ end
110
+
111
+ should "parse response into a collection of milestones" do
112
+
113
+ stub_api_get("/Payment/getAccountMilestoneList.json", "payment/get_account_milestone_list.json")
114
+ milestones = @freelancer.account_milestones
115
+ milestones.size.should == 1
116
+ milestones.first.id.should == 988
117
+
118
+ end
119
+
120
+ end
121
+
122
+ context "account withdrawal list" do
123
+
124
+ should "be able to retrieve" do
125
+
126
+ @freelancer.expects(:api_get).with("/Payment/getAccountWithdrawalList.json", {})
127
+ @freelancer.account_withdrawals
128
+
129
+ end
130
+
131
+ should "be able to retrieve by type" do
132
+
133
+ @freelancer.expects(:api_get).with("/Payment/getAccountWithdrawalList.json", { :type => "Outgoing" })
134
+ @freelancer.account_withdrawals(:type => "Outgoing")
135
+
136
+ end
137
+
138
+ should "be able to change result count" do
139
+
140
+ @freelancer.expects(:api_get).with("/Payment/getAccountWithdrawalList.json", { :count => 20 })
141
+ @freelancer.account_withdrawals(:count => 20)
142
+
143
+ end
144
+
145
+ should "be able to change result page" do
146
+
147
+ @freelancer.expects(:api_get).with("/Payment/getAccountWithdrawalList.json", { :page => 2 })
148
+ @freelancer.account_withdrawals(:page => 2)
149
+
150
+ end
151
+
152
+ should "parse response into a collection of withdrawals" do
153
+
154
+ stub_api_get("/Payment/getAccountWithdrawalList.json", "payment/get_account_withdrawal_list.json")
155
+ withdrawals = @freelancer.account_withdrawals
156
+ withdrawals.size.should == 1
157
+ withdrawals.first.id.should == 36
158
+
159
+ end
160
+
161
+ end
162
+
163
+ context "balance" do
164
+
165
+ should "be able to retrieve" do
166
+
167
+ @freelancer.expects(:api_get).with("/Payment/getBalance.json")
168
+ @freelancer.balance
169
+
170
+ end
171
+
172
+ should "return balance as a float" do
173
+
174
+ stub_api_get("/Payment/getBalance.json", "payment/get_balance.json")
175
+ balance = @freelancer.balance
176
+ balance.should == 9692.55
177
+
178
+ end
179
+
180
+ end
181
+
182
+ context "withdrawal fees" do
183
+
184
+ should "be able to retrieve" do
185
+
186
+ @freelancer.expects(:api_get).with("/Payment/getWithdrawalFees.json")
187
+ @freelancer.withdrawal_fees
188
+
189
+ end
190
+
191
+ should "parse response into a collection of withdrawal fees" do
192
+
193
+ stub_api_get("/Payment/getWithdrawalFees.json", "payment/get_withdrawal_fees.json")
194
+ fees = @freelancer.withdrawal_fees
195
+ fees.size.should == 5
196
+ fees.first.withdrawal_type.should == "paypal"
197
+
198
+ end
199
+
200
+ end
201
+
202
+
203
+ context "project list for transfer" do
204
+
205
+ should "be able to retrieve" do
206
+
207
+ @freelancer.expects(:api_get).with("/Payment/getProjectListForTransfer.json")
208
+ @freelancer.projects_for_transfer
209
+
210
+ end
211
+
212
+ should "parse response into a collection of projects" do
213
+
214
+ stub_api_get("/Payment/getProjectListForTransfer.json", "payment/get_project_list_for_transfer.json")
215
+ projects = @freelancer.projects_for_transfer
216
+ projects.size.should == 1
217
+ projects.first.id.should == 148
218
+
219
+ end
220
+
221
+ end
222
+
223
+ end
224
+
225
+ end