tenk 0.0.1 → 0.0.2

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.
@@ -0,0 +1,51 @@
1
+ require 'hashie'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module Tenk
6
+ # A base class for subresources under a project (within a /projects/:id url
7
+ # space)
8
+ class Projects::ProjectResource
9
+ def initialize(client)
10
+ @_client = client
11
+ end
12
+
13
+ # The base route for subresources under this project
14
+ # By default, infers this URL from the resource class name
15
+ # @param project_id [Integer] the id of this project
16
+ # @return [String] the base URL for the subresource
17
+ def resource_root(project_id)
18
+ "/projects/#{project_id}/#{self.class.name.demodulize.tableize}"
19
+ end
20
+
21
+ # The default implementation of list requests for project subresources
22
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
23
+ def list(project_id, options)
24
+ @_client.get(resource_root(project_id), options)
25
+ end
26
+
27
+ # The default implementation of get requests for project subresources
28
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
29
+ def get(project_id, id, options)
30
+ @_client.get("#{resource_root(project_id)}/#{id}", options)
31
+ end
32
+
33
+ # The default implementation of create requests for project subresources
34
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
35
+ def create(project_id, options)
36
+ @_client.post(resource_root(project_id), options)
37
+ end
38
+
39
+ # The default implementation of update requests for project subresources
40
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
41
+ def update(project_id, id, options)
42
+ @_client.put("#{resource_root(project_id)}/#{id}", options)
43
+ end
44
+
45
+ # The default implementation of delete requests for project subresources
46
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
47
+ def delete(project_id, id)
48
+ @_client.delete("#{resource_root(project_id)}/#{id}")
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ require 'hashie'
2
+
3
+ require_relative './project_resource'
4
+
5
+ module Tenk
6
+ # API methods for attaching and removing tags from a project
7
+ class Projects::Tags
8
+ # The valid parameters for a Tag list request
9
+ class ListRequest < ::Hashie::Trash
10
+ property :fields, default: ''
11
+ property :per_page, default: 20
12
+ property :page, default: 1
13
+ end
14
+
15
+ # Initialize a Tenk::Projects::Tag resource API wrapper for the given client
16
+ def initialize(client)
17
+ @_client = client
18
+ end
19
+
20
+ # List Tags for a single project
21
+ # @param project_id [Integer] the id of the project
22
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
23
+ # @see Tenk::Projects::Tags::ListRequest
24
+ def list(project_id)
25
+ @_client.get("/projects/#{project_id}/tags")
26
+ end
27
+
28
+ # Attach a tag to a project
29
+ # @param project_id [Integer] the id of the project
30
+ # @param tag [String] the string of the tag to attach
31
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
32
+ def add(project_id, tag)
33
+ @_client.post("/projects/#{project_id}/tags", value: tag)
34
+ end
35
+
36
+ # Remove a tag from a project
37
+ # @param project_id [Integer] the id of the project
38
+ # @param tag_id [Integer] the integer id of the tag
39
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
40
+ def remove(project_id, tag_id)
41
+ @_client.delete("/projects/#{project_id}/tags/#{tag_id}")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,58 @@
1
+ require 'hashie'
2
+
3
+ require_relative './project_resource'
4
+
5
+ module Tenk
6
+ # API methods for TimeEntries of a project
7
+ class Projects::TimeEntries < ::Tenk::Projects::ProjectResource
8
+ # The valid parameters of a list TimeEntries of project request
9
+ class ListRequest < ::Tenk::TimeEntries::ListRequest; end
10
+
11
+ # The valid parameters of a get TimeEntries of project request
12
+ class GetRequest < ::Tenk::TimeEntries::GetRequest; end
13
+
14
+ # The valid parameters of a create TimeEntries of project request
15
+ class CreateRequest < ::Tenk::TimeEntries::CreateRequest; end
16
+
17
+ # The valid parameters of a update TimeEntries of project request
18
+ class UpdateRequest < ::Tenk::TimeEntries::UpdateRequest; end
19
+
20
+ # List TimeEntries for a single project
21
+ # @param project_id [Integer] the id of the project
22
+ # @param opts [Hash] the query parameters to add to list request
23
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
24
+ # @see Tenk::Projects::TimeEntries::ListRequest
25
+ def list(project_id, opts = {})
26
+ super(project_id, ListRequest.new(opts))
27
+ end
28
+
29
+ # Get a single Assignment for this project
30
+ # @param project_id [Integer] the id of the project
31
+ # @param time_entry_id [Integer] the id of the time entry
32
+ # @param opts [Hash] the query parameters to add to the get request
33
+ # @return [Hashie::Mash] the response as a Hashie::Mash
34
+ # @see Tenk::Projects::TimeEntries::GetRequest
35
+ def get(project_id, time_entry_id, opts = {})
36
+ super(project_id, time_entry_id, GetRequest.new(opts))
37
+ end
38
+
39
+ # Create a new Assignment for this project
40
+ # @param project_id [Integer] the id of the project
41
+ # @param opts [Hash] the post parameters to add to the create request
42
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
43
+ # @see Tenk::Projects::TimeEntries::CreateRequest
44
+ def create(project_id, opts = {})
45
+ super(project_id, CreateRequest.new(opts))
46
+ end
47
+
48
+ # Update an Assignment for this project
49
+ # @param project_id [Integer] the id of the project
50
+ # @param time_entry_id [Integer] the id of the time entry
51
+ # @param opts [Hash] the post parameters to add to the create request
52
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
53
+ # @see Tenk::Projects::TimeEntries::UpdateRequest
54
+ def update(project_id, time_entry_id, opts = {})
55
+ super(project_id, time_entry_id, UpdateRequest.new(opts))
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ require 'hashie'
2
+
3
+ require_relative './project_resource'
4
+
5
+ module Tenk
6
+ # API methods for Users resource under a project, which lists users tied to
7
+ # a particular project
8
+ class Projects::Users < ::Tenk::Projects::ProjectResource
9
+ # Valid parameters for a list request of users of a project
10
+ class ListRequest < ::Hashie::Trash
11
+ property :fields, default: ''
12
+ property :per_page, default: 20
13
+ property :page, default: 1
14
+ end
15
+
16
+ # List Users for a single project
17
+ # @param project_id [Integer] the id of the project
18
+ # @param opts [Hash] the query parameters to add to list request
19
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
20
+ # @see Tenk::Projects::Users::ListRequest
21
+ def list(project_id, opts = {})
22
+ super(project_id, ListRequest.new(opts))
23
+ end
24
+ end
25
+ end
data/lib/projects.rb ADDED
@@ -0,0 +1,120 @@
1
+ require 'hashie'
2
+
3
+ module Tenk
4
+ # API methods for Project resources
5
+ class Projects < ::Tenk::Resource
6
+ # Valid parameters for a project list request
7
+ class ListRequest < ::Hashie::Trash
8
+ property :from
9
+ property :to
10
+ property :fields, default: ''
11
+ property :filter_field
12
+ property :filter_list
13
+ property :sort_field
14
+ property :sort_order
15
+ property :project_code
16
+ property :phase_name
17
+ property :with_archived, default: false
18
+ property :with_phases, default: false
19
+ property :per_page, default: 20
20
+ property :page, default: 1
21
+ end
22
+
23
+ # Valid parameters for a project get request
24
+ class GetRequest < ::Hashie::Trash
25
+ property :fields, default: ''
26
+ end
27
+
28
+ # Valid parameters for a project create request
29
+ class CreateRequest < ::Hashie::Trash
30
+ property :name
31
+ property :starts_at
32
+ property :ends_at
33
+ property :archived
34
+ property :client
35
+ property :description
36
+ property :project_code
37
+ end
38
+
39
+ # Valid parameters for a project update request
40
+ class UpdateRequest < CreateRequest
41
+ end
42
+
43
+ require_relative './projects/users'
44
+ require_relative './projects/tags'
45
+ require_relative './projects/phases'
46
+ require_relative './projects/time_entries'
47
+ require_relative './projects/assignments'
48
+ require_relative './projects/bill_rates'
49
+
50
+ # A User subresource of Projects
51
+ # @return [Projects::Users] a User subresource API class
52
+ def users
53
+ @_users ||= Projects::Users.new(@_client)
54
+ end
55
+
56
+ # A Tag subresource of Projects
57
+ # @return [Projects::Tags] a Tag subresource API class
58
+ def tags
59
+ @_tags ||= Projects::Tags.new(@_client)
60
+ end
61
+
62
+ # A Phase subresource of Projects
63
+ # @return [Projects::Phases] a Phase subresource API class
64
+ def phases
65
+ @_phases ||= Projects::Phases.new(@_client)
66
+ end
67
+
68
+ # A TimeEntry subresource of Projects
69
+ # @return [Projects::TimeEntries] a TimeEntries subresource API class
70
+ def time_entries
71
+ @_time_entries ||= Projects::TimeEntries.new(@_client)
72
+ end
73
+
74
+ # An Assignments subresource of Projects
75
+ # @return [Projects::Assignments] a Assignment subresource API class
76
+ def assignments
77
+ @_assignments ||= Projects::Assignments.new(@_client)
78
+ end
79
+
80
+ # A BillRate subresource of Projects
81
+ # @return [Projects::BillRates] a BillRate subresource API class
82
+ def bill_rates
83
+ @_bill_rates ||= Projects::BillRates.new(@_client)
84
+ end
85
+
86
+ # List projects for this 10k account
87
+ # @param opts [Hash] the query parameters for the list request
88
+ # @return [Hashie::Mash] the API response wrapped in a Hashie::Mash
89
+ # @see ListRequest
90
+ def list(opts = {})
91
+ super(ListRequest.new(opts))
92
+ end
93
+
94
+ # Get a single project for this 10k account
95
+ # @param id [Integer] the id of this project
96
+ # @param opts [Hash] the query parameters for the list request
97
+ # @return [Hashie::Mash] the API response wrapped in a Hashie::Mash
98
+ # @see GetRequest
99
+ def get(id, opts = {})
100
+ super(id, GetRequest.new(opts))
101
+ end
102
+
103
+ # Create a new project in this 10k account
104
+ # @param opts [Hash] the parameters for this create request
105
+ # @return [Hashie::Mash] the API response wrapped in a Hashie::Mash
106
+ # @see CreateRequest
107
+ def create(opts = {})
108
+ super(CreateRequest.new(opts))
109
+ end
110
+
111
+ # Update a project in this 10k account
112
+ # @param id [Integer] the id of this project
113
+ # @param opts [Hash] the parameters for this update request
114
+ # @return [Hashie::Mash] the API response wrapped in a Hashie::Mash
115
+ # @see UpdateRequest
116
+ def update(id, opts = {})
117
+ super(id, UpdateRequest.new(opts))
118
+ end
119
+ end
120
+ end
data/lib/resource.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'hashie'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module Tenk
6
+ # The base class for all API resources
7
+ class Resource
8
+ # Initialize a base API resource from the client
9
+ def initialize(client)
10
+ @_client = client
11
+ end
12
+
13
+ # The root for this resource. Default is based on class name tableized
14
+ # @return [String] the root url for actions on this resource
15
+ def resource_root
16
+ "/#{self.class.name.demodulize.tableize}"
17
+ end
18
+
19
+ # The base method for list requests on all resources
20
+ def list(options)
21
+ @_client.get(resource_root, options)
22
+ end
23
+
24
+ # The base method for get requests on all resources
25
+ def get(id, options)
26
+ @_client.get("#{resource_root}/#{id}", options)
27
+ end
28
+
29
+ # The base method for create requests on all resources
30
+ def create(options)
31
+ @_client.post(resource_root, options)
32
+ end
33
+
34
+ # The base method for update requests on all resources
35
+ def update(id, options)
36
+ @_client.put("#{resource_root}/#{id}", options)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,65 @@
1
+ require 'hashie'
2
+
3
+ module Tenk
4
+ # API methods for TimeEntries resources, which represent time that users are
5
+ # tracking against projects or phases
6
+ class TimeEntries < ::Tenk::Resource
7
+ # Valid parameters for time entry list requests
8
+ class ListRequest < ::Hashie::Trash
9
+ property :from
10
+ property :to
11
+ property :with_suggestions
12
+ property :fields
13
+ end
14
+
15
+ # Valid parameters for a time entry get requests
16
+ class GetRequest < ::Hashie::Trash; end
17
+
18
+ # Valid parameters for a time entry create requests
19
+ class CreateRequest < ::Hashie::Trash
20
+ property :user_id
21
+ property :assignable_id
22
+ property :project_id
23
+ property :leave_type_id
24
+ property :date
25
+ property :hours
26
+ property :task
27
+ property :notes
28
+ end
29
+
30
+ # Valid parameters for a time entry update requests
31
+ class UpdateRequest < CreateRequest; end
32
+
33
+ # List TimeEntries for an account
34
+ # @param opts [Hash] the filter parameters for the list
35
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
36
+ # @see ListRequest
37
+ def list(opts = {})
38
+ super(ListRequest.new(opts))
39
+ end
40
+
41
+ # Get a single TimeEntry for an account
42
+ # @param id [Integer] the id of the TimeEntry
43
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
44
+ def get(id)
45
+ super(id, {})
46
+ end
47
+
48
+ # Create a TimeEntry for this account
49
+ # @param opts [Hash] the attributes of the TimeEntry to create
50
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
51
+ # @see CreateRequest
52
+ def create(opts = {})
53
+ super(CreateRequest.new(opts))
54
+ end
55
+
56
+ # Update a TimeEntry for this account
57
+ # @param id [Integer] the id of the TimeEntry
58
+ # @param opts [Hash] the attributes of the TimeEntry to update
59
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
60
+ # @see UpdateRequest
61
+ def update(id, opts = {})
62
+ super(id, UpdateRequest.new(opts))
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,82 @@
1
+ require 'hashie'
2
+
3
+ require_relative './user_resource'
4
+
5
+ module Tenk
6
+ # The API methods for Assignments, which record that a particular person is
7
+ # assigned to a user or phase
8
+ class Users::Assignments < ::Tenk::Users::UserResource
9
+ # The valid parameters for an Assignment list request
10
+ class ListRequest < ::Hashie::Trash
11
+ property :from
12
+ property :to
13
+ property :per_page
14
+ property :page
15
+ end
16
+
17
+ # The valid parameters for an Assignment get request
18
+ class GetRequest < ::Hashie::Trash; end
19
+
20
+ # The valid parameters for an Assignment create request
21
+ class CreateRequest < ::Hashie::Trash
22
+ property :project_id
23
+ property :assignable_id
24
+ property :leave_type_id
25
+ property :starts_at
26
+ property :ends_at
27
+ property :percent
28
+ property :fixed_hours
29
+ property :hours_per_day
30
+ property :allocation_mode
31
+ end
32
+
33
+ # The valid parameters for an Assignment update request
34
+ class UpdateRequest < CreateRequest; end
35
+
36
+ # List Assignments for a single user
37
+ # @param user_id [Integer] the id of the user
38
+ # @param opts [Hash] the query parameters to add to list request
39
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
40
+ # @see Tenk::Users::Assignments::ListRequest
41
+ def list(user_id, opts = {})
42
+ super(user_id, ListRequest.new(opts))
43
+ end
44
+
45
+ # Get a single Assignment for this user
46
+ # @param user_id [Integer] the id of the user
47
+ # @param assignment_id [Integer] the id of the assignment
48
+ # @param opts [Hash] the query parameters to add to the get request
49
+ # @return [Hashie::Mash] the response as a Hashie::Mash
50
+ # @see Tenk::Users::Assignments::GetRequest
51
+ def get(user_id, assignment_id, opts = {})
52
+ super(user_id, assignment_id, GetRequest.new(opts))
53
+ end
54
+
55
+ # Create a new Assignment for this user
56
+ # @param user_id [Integer] the id of the user
57
+ # @param opts [Hash] the post parameters to add to the create request
58
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
59
+ # @see Tenk::Users::Assignments::CreateRequest
60
+ def create(user_id, opts = {})
61
+ super(user_id, CreateRequest.new(opts))
62
+ end
63
+
64
+ # Update an Assignment for this user
65
+ # @param user_id [Integer] the id of the user
66
+ # @param assignment_id [Integer] the id of the assignment
67
+ # @param opts [Hash] the post parameters to add to the create request
68
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
69
+ # @see Tenk::Users::Assignments::UpdateRequest
70
+ def update(user_id, assignment_id, opts = {})
71
+ super(user_id, assignment_id, UpdateRequest.new(opts))
72
+ end
73
+
74
+ # Delete an Assignment for this user
75
+ # @param user_id [Integer] the id of the user
76
+ # @param assignment_id [Integer] the id of the assignment
77
+ # @return [bool] true if successful
78
+ def delete(user_id, assignment_id)
79
+ super(user_id, assignment_id)
80
+ end
81
+ end
82
+ end
data/lib/users/tags.rb ADDED
@@ -0,0 +1,33 @@
1
+ module Tenk
2
+ # API methods for listing, adding, and removing tags for users
3
+ class Tags
4
+ # Initialize a Tenk::Users::Tag resource API wrapper for the given client
5
+ def initialize(client)
6
+ @_client = client
7
+ end
8
+
9
+ # List Tags for a single user
10
+ # @param user_id [Integer] the id of the user
11
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
12
+ # @see Tenk::Users::Tags::ListRequest
13
+ def list(user_id)
14
+ @_client.get("/users/#{user_id}/tags")
15
+ end
16
+
17
+ # Attach a tag to a user
18
+ # @param user_id [Integer] the id of the user
19
+ # @param tag [String] the string of the tag to attach
20
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
21
+ def add(user_id, tag)
22
+ @_client.post("/users/#{user_id}/tags", value: tag)
23
+ end
24
+
25
+ # Remove a tag from a user
26
+ # @param user_id [Integer] the id of the user
27
+ # @param tag_id [Integer] the integer id of the tag
28
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
29
+ def remove(user_id, tag_id)
30
+ @_client.delete("/users/#{user_id}/tags/#{tag_id}")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,58 @@
1
+ require 'hashie'
2
+
3
+ require_relative './user_resource'
4
+
5
+ module Tenk
6
+ # API methods for TimeEntries resources for a particular user
7
+ class Users::TimeEntries < ::Tenk::Users::UserResource
8
+ # Valid parameters for a list request of time entries of a user
9
+ class ListRequest < ::Tenk::TimeEntries::ListRequest; end
10
+
11
+ # Valid parameters for a get request of time entries of a user
12
+ class GetRequest < ::Tenk::TimeEntries::GetRequest; end
13
+
14
+ # Valid parameters for a create request of time entries of a user
15
+ class CreateRequest < ::Tenk::TimeEntries::CreateRequest; end
16
+
17
+ # Valid parameters for a update request of time entries of a user
18
+ class UpdateRequest < ::Tenk::TimeEntries::UpdateRequest; end
19
+
20
+ # List TimeEntries for a single user
21
+ # @param user_id [Integer] the id of the user
22
+ # @param opts [Hash] the query parameters to add to list request
23
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
24
+ # @see Tenk::Users::TimeEntries::ListRequest
25
+ def list(user_id, opts = {})
26
+ super(user_id, ListRequest.new(opts))
27
+ end
28
+
29
+ # Get a single TimeEntry for this user
30
+ # @param user_id [Integer] the id of the user
31
+ # @param time_entry_id [Integer] the id of the time entry
32
+ # @param opts [Hash] the query parameters to add to the get request
33
+ # @return [Hashie::Mash] the response as a Hashie::Mash
34
+ # @see Tenk::Users::TimeEntries::GetRequest
35
+ def get(user_id, time_entry_id, opts = {})
36
+ super(user_id, time_entry_id, GetRequest.new(opts))
37
+ end
38
+
39
+ # Create a new TimeEntry for this user
40
+ # @param user_id [Integer] the id of the user
41
+ # @param opts [Hash] the post parameters to add to the create request
42
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
43
+ # @see Tenk::Users::TimeEntries::CreateRequest
44
+ def create(user_id, opts = {})
45
+ super(user_id, CreateRequest.new(opts))
46
+ end
47
+
48
+ # Update an TimeEntry for this user
49
+ # @param user_id [Integer] the id of the user
50
+ # @param time_entry_id [Integer] the id of the time entry
51
+ # @param opts [Hash] the post parameters to add to the create request
52
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
53
+ # @see Tenk::Users::TimeEntries::UpdateRequest
54
+ def update(user_id, time_entry_id, opts = {})
55
+ super(user_id, time_entry_id, UpdateRequest.new(opts))
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,50 @@
1
+ require 'hashie'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module Tenk
6
+ # A base model for API resources nested under a user (/users/:id subresources)
7
+ class Users::UserResource
8
+ def initialize(client)
9
+ @_client = client
10
+ end
11
+
12
+ # The base route for subresources under this user
13
+ # By default, infers this URL from the resource class name
14
+ # @param user_id [Integer] the id of this user
15
+ # @return [String] the base URL for the subresource
16
+ def resource_root(user_id)
17
+ "/users/#{user_id}/#{self.class.name.demodulize.tableize}"
18
+ end
19
+
20
+ # The default implementation of list requests for user subresources
21
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
22
+ def list(user_id, options)
23
+ @_client.get(resource_root(user_id), options)
24
+ end
25
+
26
+ # The default implementation of get requests for user subresources
27
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
28
+ def get(user_id, id, options)
29
+ @_client.get("#{resource_root(user_id)}/#{id}", options)
30
+ end
31
+
32
+ # The default implementation of create requests for user subresources
33
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
34
+ def create(user_id, options)
35
+ @_client.post(resource_root(user_id), options)
36
+ end
37
+
38
+ # The default implementation of update requests for user subresources
39
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
40
+ def update(user_id, id, options)
41
+ @_client.put("#{resource_root(user_id)}/#{id}", options)
42
+ end
43
+
44
+ # The default implementation of delete requests for user subresources
45
+ # @return [Hashie::Mash] the API response as a Hashie::Mash
46
+ def delete(user_id, id)
47
+ @_client.delete("#{resource_root(user_id)}/#{id}")
48
+ end
49
+ end
50
+ end