rexpense 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +22 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.rubocop.yml +54 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +97 -0
- data/LICENSE.txt +21 -0
- data/README.md +195 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +21 -0
- data/bin/setup +7 -0
- data/lib/rexpense/client.rb +39 -0
- data/lib/rexpense/configuration.rb +13 -0
- data/lib/rexpense/entities/activity.rb +11 -0
- data/lib/rexpense/entities/activity_collection.rb +14 -0
- data/lib/rexpense/entities/advancement.rb +14 -0
- data/lib/rexpense/entities/advancement_collection.rb +14 -0
- data/lib/rexpense/entities/advancement_devolution.rb +13 -0
- data/lib/rexpense/entities/attachment.rb +13 -0
- data/lib/rexpense/entities/attachment_collection.rb +14 -0
- data/lib/rexpense/entities/base.rb +9 -0
- data/lib/rexpense/entities/collection.rb +65 -0
- data/lib/rexpense/entities/comment.rb +13 -0
- data/lib/rexpense/entities/comment_collection.rb +14 -0
- data/lib/rexpense/entities/expense.rb +22 -0
- data/lib/rexpense/entities/expense_collection.rb +14 -0
- data/lib/rexpense/entities/membership.rb +10 -0
- data/lib/rexpense/entities/membership_collection.rb +14 -0
- data/lib/rexpense/entities/organization.rb +14 -0
- data/lib/rexpense/entities/organization_collection.rb +14 -0
- data/lib/rexpense/entities/pre_expense.rb +17 -0
- data/lib/rexpense/entities/pre_expense_collection.rb +14 -0
- data/lib/rexpense/entities/reimbursement.rb +14 -0
- data/lib/rexpense/entities/reimbursement_collection.rb +14 -0
- data/lib/rexpense/entities/tag.rb +8 -0
- data/lib/rexpense/entities/tag_collection.rb +14 -0
- data/lib/rexpense/entities/user.rb +14 -0
- data/lib/rexpense/entities/user_collection.rb +14 -0
- data/lib/rexpense/entities/webhook.rb +10 -0
- data/lib/rexpense/entities/webhook_collection.rb +14 -0
- data/lib/rexpense/exception.rb +11 -0
- data/lib/rexpense/http.rb +41 -0
- data/lib/rexpense/request.rb +56 -0
- data/lib/rexpense/resources/activity.rb +24 -0
- data/lib/rexpense/resources/advancement.rb +20 -0
- data/lib/rexpense/resources/advancement_devolution.rb +36 -0
- data/lib/rexpense/resources/base.rb +52 -0
- data/lib/rexpense/resources/expense.rb +39 -0
- data/lib/rexpense/resources/nested_endpoints/attachment.rb +48 -0
- data/lib/rexpense/resources/nested_endpoints/comment.rb +84 -0
- data/lib/rexpense/resources/nested_endpoints/membership.rb +74 -0
- data/lib/rexpense/resources/nested_endpoints/participant.rb +43 -0
- data/lib/rexpense/resources/organization.rb +31 -0
- data/lib/rexpense/resources/pre_expense.rb +56 -0
- data/lib/rexpense/resources/reimbursement.rb +20 -0
- data/lib/rexpense/resources/resource_base.rb +105 -0
- data/lib/rexpense/resources/tag.rb +82 -0
- data/lib/rexpense/resources/webhook.rb +82 -0
- data/lib/rexpense/response.rb +43 -0
- data/lib/rexpense/version.rb +3 -0
- data/lib/rexpense.rb +19 -0
- data/rexpense.gemspec +48 -0
- data/spec/lib/rexpense/client_spec.rb +47 -0
- data/spec/lib/rexpense/configuration_spec.rb +26 -0
- data/spec/lib/rexpense/entities/activity_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/activity_spec.rb +9 -0
- data/spec/lib/rexpense/entities/advancement_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/advancement_devolution_spec.rb +9 -0
- data/spec/lib/rexpense/entities/advancement_spec.rb +10 -0
- data/spec/lib/rexpense/entities/base_spec.rb +28 -0
- data/spec/lib/rexpense/entities/collection_spec.rb +70 -0
- data/spec/lib/rexpense/entities/comment_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/comment_spec.rb +10 -0
- data/spec/lib/rexpense/entities/expense_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/expense_spec.rb +14 -0
- data/spec/lib/rexpense/entities/membership_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/membership_spec.rb +7 -0
- data/spec/lib/rexpense/entities/organization_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/organization_spec.rb +8 -0
- data/spec/lib/rexpense/entities/pre_expense_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/pre_expense_spec.rb +10 -0
- data/spec/lib/rexpense/entities/reimbursement_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/reimbursement_spec.rb +10 -0
- data/spec/lib/rexpense/entities/user_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/user_spec.rb +10 -0
- data/spec/lib/rexpense/entities/webhook_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/webhook_spec.rb +7 -0
- data/spec/lib/rexpense/http_spec.rb +37 -0
- data/spec/lib/rexpense/request_spec.rb +29 -0
- data/spec/lib/rexpense/resources/activity_spec.rb +16 -0
- data/spec/lib/rexpense/resources/advancement_devolution_spec.rb +29 -0
- data/spec/lib/rexpense/resources/advancement_spec.rb +207 -0
- data/spec/lib/rexpense/resources/expense_spec.rb +227 -0
- data/spec/lib/rexpense/resources/organization_spec.rb +162 -0
- data/spec/lib/rexpense/resources/pre_expense_spec.rb +83 -0
- data/spec/lib/rexpense/resources/reimbursement_spec.rb +207 -0
- data/spec/lib/rexpense/resources/tag_specs.rb +77 -0
- data/spec/lib/rexpense/resources/webhook_spec.rb +51 -0
- data/spec/lib/rexpense/response_spec.rb +91 -0
- data/spec/lib/rexpense_spec.rb +34 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/attachments/logo.png +0 -0
- data/spec/support/client.rb +3 -0
- data/spec/support/matchers/have_attr_accessor.rb +18 -0
- data/spec/support/shared_examples/entity_attributes.rb +9 -0
- data/spec/support/shared_examples/entity_collection.rb +19 -0
- data/spec/support/shared_examples/http_request_methods.rb +35 -0
- data/spec/support/vcr.rb +7 -0
- metadata +390 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
module Rexpense::Resources
|
2
|
+
module Comment
|
3
|
+
#
|
4
|
+
# Get resource comments
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Method: <tt>GET /api/v1/reimbursements/:id/comments</tt>
|
8
|
+
# Method: <tt>GET /api/v1/expenses/:id/comments</tt>
|
9
|
+
# Method: <tt>GET /api/v1/advancements/:id/comments</tt>
|
10
|
+
#
|
11
|
+
# Documentation: http://developers.rexpense.com/api/comments#index
|
12
|
+
def comments(resource_id)
|
13
|
+
http.get(comment_endpoint(resource_id)) do |response|
|
14
|
+
Rexpense::Entities::CommentCollection.build response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Get resource comment
|
20
|
+
#
|
21
|
+
# [API]
|
22
|
+
# Method: <tt>GET /api/v1/reimbursements/:id/comments/:comment_id</tt>
|
23
|
+
# Method: <tt>GET /api/v1/expenses/:id/comments/:comment_id</tt>
|
24
|
+
# Method: <tt>GET /api/v1/advancements/:id/comments/:comment_id</tt>
|
25
|
+
#
|
26
|
+
# Documentation: http://developers.rexpense.com/api/comments#show
|
27
|
+
def find_comment(resource_id, comment_id)
|
28
|
+
http.get("#{comment_endpoint(resource_id)}/#{comment_id}") do |response|
|
29
|
+
Rexpense::Entities::Comment.new response.parsed_body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Create resource comment
|
35
|
+
#
|
36
|
+
# [API]
|
37
|
+
# Method: <tt>POST /api/v1/reimbursements/:id/comments</tt>
|
38
|
+
# Method: <tt>POST /api/v1/expenses/:id/comments</tt>
|
39
|
+
# Method: <tt>POST /api/v1/advancements/:id/comments</tt>
|
40
|
+
#
|
41
|
+
# Documentation: http://developers.rexpense.com/api/comments#create
|
42
|
+
def create_comment(resource_id, params)
|
43
|
+
http.post(comment_endpoint(resource_id), body: params) do |response|
|
44
|
+
Rexpense::Entities::Comment.new response.parsed_body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Update resource comment
|
50
|
+
#
|
51
|
+
# [API]
|
52
|
+
# Method: <tt>PUT /api/v1/reimbursements/:id/comments/:comment_id</tt>
|
53
|
+
# Method: <tt>PUT /api/v1/expenses/:id/comments/:comment_id</tt>
|
54
|
+
# Method: <tt>PUT /api/v1/advancements/:id/comments/:comment_id</tt>
|
55
|
+
#
|
56
|
+
# Documentation: http://developers.rexpense.com/api/comments#update
|
57
|
+
def update_comment(resource_id, comment_id, params)
|
58
|
+
http.put("#{comment_endpoint(resource_id)}/#{comment_id}", body: params) do |response|
|
59
|
+
Rexpense::Entities::Comment.new response.parsed_body
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Destroy resource comment
|
65
|
+
#
|
66
|
+
# [API]
|
67
|
+
# Method: <tt>DELETE /api/v1/reimbursements/:id/comments/:comment_id</tt>
|
68
|
+
# Method: <tt>DELETE /api/v1/expenses/:id/comments/:comment_id</tt>
|
69
|
+
# Method: <tt>DELETE /api/v1/advancements/:id/comments/:comment_id</tt>
|
70
|
+
#
|
71
|
+
# Documentation: http://developers.rexpense.com/api/comments#destroy
|
72
|
+
def destroy_comment(resource_id, comment_id)
|
73
|
+
http.delete("#{comment_endpoint(resource_id)}/#{comment_id}") do |response|
|
74
|
+
true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def comment_endpoint(resource_id)
|
81
|
+
"#{endpoint_base}/#{resource_id}/comments"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Rexpense::Resources
|
2
|
+
module Membership
|
3
|
+
#
|
4
|
+
# Get organization memberships
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Method: <tt>GET /api/v1/organizations/:id/memberships</tt>
|
8
|
+
#
|
9
|
+
# Documentation: http://developers.rexpense.com/api/memberships#index
|
10
|
+
def memberships(organization_id)
|
11
|
+
http.get(membership_endpoint(organization_id)) do |response|
|
12
|
+
Rexpense::Entities::MembershipCollection.build response
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Get organization membership
|
18
|
+
#
|
19
|
+
# [API]
|
20
|
+
# Method: <tt>GET /api/v1/organizations/:id/memberships/:membership_id</tt>
|
21
|
+
#
|
22
|
+
# Documentation: http://developers.rexpense.com/api/memberships#show
|
23
|
+
def find_membership(organization_id, membership_id)
|
24
|
+
http.get("#{membership_endpoint(organization_id)}/#{membership_id}") do |response|
|
25
|
+
Rexpense::Entities::Membership.new response.parsed_body
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Create organization membership
|
31
|
+
#
|
32
|
+
# [API]
|
33
|
+
# Method: <tt>POST /api/v1/organizations/:id/memberships</tt>
|
34
|
+
#
|
35
|
+
# Documentation: http://developers.rexpense.com/api/memberships#create
|
36
|
+
def create_membership(organization_id, params)
|
37
|
+
http.post(membership_endpoint(organization_id), body: params) do |response|
|
38
|
+
response.parsed_body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Update organization membership
|
44
|
+
#
|
45
|
+
# [API]
|
46
|
+
# Method: <tt>PUT /api/v1/organizations/:id/memberships/:membership_id</tt>
|
47
|
+
#
|
48
|
+
# Documentation: http://developers.rexpense.com/api/memberships#update
|
49
|
+
def update_membership(organization_id, membership_id, params)
|
50
|
+
http.put("#{membership_endpoint(organization_id)}/#{membership_id}", body: params) do |response|
|
51
|
+
Rexpense::Entities::Membership.new response.parsed_body
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Destroy organization membership
|
57
|
+
#
|
58
|
+
# [API]
|
59
|
+
# Method: <tt>DELETE /api/v1/organizations/:id/memberships/:membership_id</tt>
|
60
|
+
#
|
61
|
+
# Documentation: http://developers.rexpense.com/api/memberships#destroy
|
62
|
+
def destroy_membership(organization_id, membership_id)
|
63
|
+
http.delete("#{membership_endpoint(organization_id)}/#{membership_id}") do |response|
|
64
|
+
true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def membership_endpoint(organization_id)
|
71
|
+
"#{endpoint_base}/#{organization_id}/members"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rexpense::Resources
|
2
|
+
module Participant
|
3
|
+
#
|
4
|
+
# Get resource participants tags
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Method: <tt>GET /api/v1/reimbursements/:id/participants</tt>
|
8
|
+
# Method: <tt>GET /api/v1/expenses/:id/participants</tt>
|
9
|
+
# Method: <tt>GET /api/v1/advancements/:id/participants</tt>
|
10
|
+
#
|
11
|
+
# Documentation: http://developers.rexpense.com/api/participants#index
|
12
|
+
# Documentation: http://developers.rexpense.com/api/expense_participants#index
|
13
|
+
# Documentation: http://developers.rexpense.com/api/reimbursement_participants#index
|
14
|
+
def participants(resource_id)
|
15
|
+
http.get(participants_endpoint(resource_id)) do |response|
|
16
|
+
Rexpense::Entities::UserCollection.build response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Get resource participants tags
|
22
|
+
#
|
23
|
+
# [API]
|
24
|
+
# Method: <tt>GET /api/v1/reimbursements/:id/participants</tt>
|
25
|
+
# Method: <tt>GET /api/v1/expenses/:id/participants</tt>
|
26
|
+
# Method: <tt>GET /api/v1/advancements/:id/participants</tt>
|
27
|
+
#
|
28
|
+
# Documentation: http://developers.rexpense.com/api/advancement_participants#destroy
|
29
|
+
# Documentation: http://developers.rexpense.com/api/expense_participants#destroy
|
30
|
+
# Documentation: http://developers.rexpense.com/api/reimbursement_participants#destroy
|
31
|
+
def leave_participant(resource_id)
|
32
|
+
http.delete(participants_endpoint(resource_id)) do |response|
|
33
|
+
true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def participants_endpoint(resource_id)
|
40
|
+
"#{endpoint_base}/#{resource_id}/participants"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rexpense
|
2
|
+
module Resources
|
3
|
+
#
|
4
|
+
# A wrapper to Rexpense organizations API
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Documentation: http://developers.rexpense.com/api/v1/organizations/
|
8
|
+
#
|
9
|
+
class Organization < ResourceBase
|
10
|
+
include Rexpense::Resources::Membership
|
11
|
+
|
12
|
+
def distances_rules(id)
|
13
|
+
http.get("#{endpoint_base}/#{id}/distances_rules") do |response|
|
14
|
+
response.parsed_body.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_distances_rules(id, params)
|
19
|
+
http.post("#{endpoint_base}/#{id}/distances_rules", body: params) do |response|
|
20
|
+
response.parsed_body.first
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def endpoint_base
|
27
|
+
"/organizations"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Rexpense
|
2
|
+
module Resources
|
3
|
+
#
|
4
|
+
# A wrapper to Rexpense pre_expenses API
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Documentation: http://developers.rexpense.com/api/v1/pre_expenses/
|
8
|
+
#
|
9
|
+
class PreExpense < ResourceBase
|
10
|
+
#
|
11
|
+
# Ignore a pre_expense resource
|
12
|
+
#
|
13
|
+
# [API]
|
14
|
+
# Method: <tt>PUT /api/v1/pre_expenses/ignore</tt>
|
15
|
+
#
|
16
|
+
# Documentation: http://developers.rexpense.com/api/v1/pre_expenses/#ignore
|
17
|
+
def ignore(id)
|
18
|
+
http.put("#{endpoint_base}/#{id}/ignore") do |response|
|
19
|
+
respond_with_object response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Restore a pre_expense resource
|
25
|
+
#
|
26
|
+
# [API]
|
27
|
+
# Method: <tt>PUT /api/v1/pre_expenses/restore</tt>
|
28
|
+
#
|
29
|
+
# Documentation: http://developers.rexpense.com/api/v1/pre_expenses/#ignore
|
30
|
+
def restore(id)
|
31
|
+
http.put("#{endpoint_base}/#{id}/restore") do |response|
|
32
|
+
respond_with_object response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Restore a pre_expense resource
|
38
|
+
#
|
39
|
+
# [API]
|
40
|
+
# Method: <tt>POST /api/v1/pre_expenses/convert</tt>
|
41
|
+
#
|
42
|
+
# Documentation: http://developers.rexpense.com/api/v1/pre_expenses/#convert
|
43
|
+
def convert(id, params={})
|
44
|
+
http.post("#{endpoint_base}/#{id}/convert", body: params) do |response|
|
45
|
+
Rexpense::Entities::Expense.new response.parsed_body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def endpoint_base
|
52
|
+
"/pre_expenses"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rexpense
|
2
|
+
module Resources
|
3
|
+
#
|
4
|
+
# A wrapper to Rexpense reimbursements API
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Documentation: http://developers.rexpense.com/api/v1/reimbursements/
|
8
|
+
#
|
9
|
+
class Reimbursement < ResourceBase
|
10
|
+
include Rexpense::Resources::Comment
|
11
|
+
include Rexpense::Resources::Participant
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def endpoint_base
|
16
|
+
"/reimbursements"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Rexpense
|
2
|
+
module Resources
|
3
|
+
#
|
4
|
+
# A wrapper to Rexpense resources API
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Documentation: http://developers.rexpense.com/api/v1/expenses/
|
8
|
+
# Documentation: http://developers.rexpense.com/api/v1/advancements/
|
9
|
+
# Documentation: http://developers.rexpense.com/api/v1/reimbursements/
|
10
|
+
#
|
11
|
+
class ResourceBase < Base
|
12
|
+
#
|
13
|
+
# List all resources
|
14
|
+
#
|
15
|
+
# [API]
|
16
|
+
# Method: <tt>GET /api/v1/expenses</tt>
|
17
|
+
# Method: <tt>GET /api/v1/advancements</tt>
|
18
|
+
# Method: <tt>GET /api/v1/reimbursements</tt>
|
19
|
+
#
|
20
|
+
# Documentation: http://developers.rexpense.com/api/v1/expenses/#index
|
21
|
+
# Documentation: http://developers.rexpense.com/api/v1/advancements/#index
|
22
|
+
# Documentation: http://developers.rexpense.com/api/v1/reimbursements/#index
|
23
|
+
#
|
24
|
+
def find_all(params = {})
|
25
|
+
search_endpoint = build_search_endpoint(params)
|
26
|
+
|
27
|
+
http.get(search_endpoint) do |response|
|
28
|
+
respond_with_collection(response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Find a resource
|
34
|
+
#
|
35
|
+
# [API]
|
36
|
+
# Method: <tt>GET /api/v1/expenses/:id</tt>
|
37
|
+
# Method: <tt>GET /api/v1/advancements/:id</tt>
|
38
|
+
# Method: <tt>GET /api/v1/reimbursements/:id</tt>
|
39
|
+
#
|
40
|
+
# Documentation: http://developers.rexpense.com/api/v1/expenses/#show
|
41
|
+
# Documentation: http://developers.rexpense.com/api/v1/advancements/#show
|
42
|
+
# Documentation: http://developers.rexpense.com/api/v1/reimbursements/#show
|
43
|
+
#
|
44
|
+
def find(id)
|
45
|
+
http.get("#{endpoint_base}/#{id}", body: {}) do |response|
|
46
|
+
respond_with_object response
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Create a resource
|
52
|
+
#
|
53
|
+
# [API]
|
54
|
+
# Method: <tt>POST /api/v1/expenses</tt>
|
55
|
+
# Method: <tt>POST /api/v1/advancements</tt>
|
56
|
+
# Method: <tt>POST /api/v1/reimbursements</tt>
|
57
|
+
#
|
58
|
+
# Documentation: http://developers.rexpense.com/api/v1/expenses/#create
|
59
|
+
# Documentation: http://developers.rexpense.com/api/v1/advancements/#create
|
60
|
+
# Documentation: http://developers.rexpense.com/api/v1/reimbursements/#create
|
61
|
+
#
|
62
|
+
def create(params)
|
63
|
+
http.post("#{endpoint_base}", body: params) do |response|
|
64
|
+
respond_with_object response
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Updates a resource
|
70
|
+
#
|
71
|
+
# [API]
|
72
|
+
# Method: <tt>PATCH /api/v1/expenses/:id</tt>
|
73
|
+
# Method: <tt>PATCH /api/v1/advancements/:id</tt>
|
74
|
+
# Method: <tt>PATCH /api/v1/reimbursements/:id</tt>
|
75
|
+
#
|
76
|
+
# Documentation: http://developers.rexpense.com/api/v1/expenses/#update
|
77
|
+
# Documentation: http://developers.rexpense.com/api/v1/advancements/#update
|
78
|
+
# Documentation: http://developers.rexpense.com/api/v1/reimbursements/#update
|
79
|
+
#
|
80
|
+
def update(id, params = {})
|
81
|
+
http.patch("#{endpoint_base}/#{id}", body: params) do |response|
|
82
|
+
respond_with_object response
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Destroy a resource
|
88
|
+
#
|
89
|
+
# [API]
|
90
|
+
# Method: <tt>DELETE /api/v1/expenses/:id</tt>
|
91
|
+
# Method: <tt>DELETE /api/v1/advancements/:id</tt>
|
92
|
+
# Method: <tt>DELETE /api/v1/reimbursements/:id</tt>
|
93
|
+
#
|
94
|
+
# Documentation: http://developers.rexpense.com/api/v1/expenses/#destroy
|
95
|
+
# Documentation: http://developers.rexpense.com/api/v1/advancements/#destroy
|
96
|
+
# Documentation: http://developers.rexpense.com/api/v1/reimbursements/#destroy
|
97
|
+
#
|
98
|
+
def destroy(id)
|
99
|
+
http.delete("#{endpoint_base}/#{id}", body: {}) do |response|
|
100
|
+
true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Rexpense
|
2
|
+
module Resources
|
3
|
+
#
|
4
|
+
# A wrapper to Rexpense Tag API
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Documentation: http://developers.rexpense.com/api/v1/tags
|
8
|
+
#
|
9
|
+
class Tag < ResourceBase
|
10
|
+
#
|
11
|
+
# Get organization tags
|
12
|
+
#
|
13
|
+
# [API]
|
14
|
+
# Method: <tt>GET /api/v1/organization/:id/tags</tt>
|
15
|
+
#
|
16
|
+
# Documentation: http://developers.rexpense.com/api/tags#index
|
17
|
+
def find_all(id)
|
18
|
+
http.get(endpoint_base(id)) do |response|
|
19
|
+
Rexpense::Entities::TagCollection.build response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Find a organization tag
|
25
|
+
#
|
26
|
+
# [API]
|
27
|
+
# Method: <tt>GET /api/v1/organization/:id/tags/:tag_id</tt>
|
28
|
+
#
|
29
|
+
# Documentation: http://developers.rexpense.com/api/tags#show
|
30
|
+
def find(id, tag_id)
|
31
|
+
http.get("#{endpoint_base(id)}/#{tag_id}") do |response|
|
32
|
+
Rexpense::Entities::Tag.new response.parsed_body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Create a organization tag
|
38
|
+
#
|
39
|
+
# [API]
|
40
|
+
# Method: <tt>POST /api/v1/organization/:id/tags</tt>
|
41
|
+
#
|
42
|
+
# Documentation: http://developers.rexpense.com/api/tags#create
|
43
|
+
def create(id, params={})
|
44
|
+
http.post(endpoint_base(id), body: params) do |response|
|
45
|
+
Rexpense::Entities::Tag.new response.parsed_body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Update a organization tag
|
51
|
+
#
|
52
|
+
# [API]
|
53
|
+
# Method: <tt>PUT /api/v1/organization/:id/tags/:tag_id</tt>
|
54
|
+
#
|
55
|
+
# Documentation: http://developers.rexpense.com/api/tags#update
|
56
|
+
def update(id, tag_id, params={})
|
57
|
+
http.put("#{endpoint_base(id)}/#{tag_id}", body: params) do |response|
|
58
|
+
Rexpense::Entities::Tag.new response.parsed_body
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Create a organization tag
|
64
|
+
#
|
65
|
+
# [API]
|
66
|
+
# Method: <tt>DELETE /api/v1/organization/:id/tags/:tag_id</tt>
|
67
|
+
#
|
68
|
+
# Documentation: http://developers.rexpense.com/api/tags#destroy
|
69
|
+
def destroy(id, tag_id)
|
70
|
+
http.delete("#{endpoint_base(id)}/#{tag_id}") do |response|
|
71
|
+
true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def endpoint_base(id)
|
78
|
+
"/organizations/#{id}/tags"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Rexpense
|
2
|
+
module Resources
|
3
|
+
#
|
4
|
+
# A wrapper to Rexpense organizations API
|
5
|
+
#
|
6
|
+
# [API]
|
7
|
+
# Documentation: http://developers.rexpense.com/api/v1/organizations/
|
8
|
+
#
|
9
|
+
class Webhook < Base
|
10
|
+
#
|
11
|
+
# Get organization webhooks
|
12
|
+
#
|
13
|
+
# [API]
|
14
|
+
# Method: <tt>GET /api/v1/organization/:id/integrations/webhooks</tt>
|
15
|
+
#
|
16
|
+
# Documentation: http://developers.rexpense.com/api/webhooks#index
|
17
|
+
def find_all(id)
|
18
|
+
http.get(endpoint_base(id)) do |response|
|
19
|
+
Rexpense::Entities::WebhookCollection.build response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Find a organization Webhook
|
25
|
+
#
|
26
|
+
# [API]
|
27
|
+
# Method: <tt>GET /api/v1/organization/:id/integrations/webhooks/:webhook_id</tt>
|
28
|
+
#
|
29
|
+
# Documentation: http://developers.rexpense.com/api/webhooks#show
|
30
|
+
def find(id, webhook_id)
|
31
|
+
http.get("#{endpoint_base(id)}/#{webhook_id}") do |response|
|
32
|
+
Rexpense::Entities::Webhook.new response.parsed_body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Create a organization Webhook
|
38
|
+
#
|
39
|
+
# [API]
|
40
|
+
# Method: <tt>POST /api/v1/organization/:id/integrations/webhooks</tt>
|
41
|
+
#
|
42
|
+
# Documentation: http://developers.rexpense.com/api/webhooks#create
|
43
|
+
def create(id, params={})
|
44
|
+
http.post(endpoint_base(id), body: params) do |response|
|
45
|
+
Rexpense::Entities::Webhook.new response.parsed_body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Update a organization Webhook
|
51
|
+
#
|
52
|
+
# [API]
|
53
|
+
# Method: <tt>PUT /api/v1/organization/:id/integrations/webhooks/:webhook_id</tt>
|
54
|
+
#
|
55
|
+
# Documentation: http://developers.rexpense.com/api/webhooks#update
|
56
|
+
def update(id, webhook_id, params={})
|
57
|
+
http.put("#{endpoint_base(id)}/#{webhook_id}", body: params) do |response|
|
58
|
+
Rexpense::Entities::Webhook.new response.parsed_body
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Create a organization Webhook
|
64
|
+
#
|
65
|
+
# [API]
|
66
|
+
# Method: <tt>DELETE /api/v1/organization/:id/integrations/webhooks/:webhook_id</tt>
|
67
|
+
#
|
68
|
+
# Documentation: http://developers.rexpense.com/api/webhooks#destroy
|
69
|
+
def destroy(id, webhook_id)
|
70
|
+
http.delete("#{endpoint_base(id)}/#{webhook_id}") do |response|
|
71
|
+
true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def endpoint_base(id)
|
78
|
+
"/organizations/#{id}/integrations/webhooks"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rexpense/exception"
|
2
|
+
|
3
|
+
module Rexpense
|
4
|
+
class RequestTimeout < Exception; end
|
5
|
+
class RequestError < Exception; end
|
6
|
+
|
7
|
+
class Response < SimpleDelegator
|
8
|
+
def resolve!
|
9
|
+
if success?
|
10
|
+
block_given? ? yield(self) : self
|
11
|
+
elsif timed_out?
|
12
|
+
raise RequestTimeout
|
13
|
+
else
|
14
|
+
error!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def parsed_body(key = nil)
|
19
|
+
return JSON.parse(body)[key] unless key.nil?
|
20
|
+
JSON.parse(body)
|
21
|
+
rescue JSON::ParserError
|
22
|
+
{}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def error!
|
28
|
+
raise RequestError.new(
|
29
|
+
code: code,
|
30
|
+
message: request_error_message,
|
31
|
+
body: parsed_body
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def request_error_message
|
36
|
+
if !status_message.nil? && status_message != ""
|
37
|
+
status_message
|
38
|
+
else
|
39
|
+
parsed_body["error"] || ""
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/rexpense.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "typhoeus"
|
2
|
+
require "mime/types"
|
3
|
+
require "require_all"
|
4
|
+
|
5
|
+
require_rel "rexpense"
|
6
|
+
|
7
|
+
module Rexpense
|
8
|
+
def self.configuration
|
9
|
+
@configuration ||= Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
yield(configuration) if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.client(token)
|
17
|
+
Client.new(token)
|
18
|
+
end
|
19
|
+
end
|