clio_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +169 -0
  5. data/Rakefile +9 -0
  6. data/clio_client.gemspec +27 -0
  7. data/lib/clio_client/api/activity.rb +23 -0
  8. data/lib/clio_client/api/activity_description.rb +17 -0
  9. data/lib/clio_client/api/base.rb +18 -0
  10. data/lib/clio_client/api/bill.rb +23 -0
  11. data/lib/clio_client/api/calendar.rb +19 -0
  12. data/lib/clio_client/api/calendar_entry.rb +20 -0
  13. data/lib/clio_client/api/communication.rb +25 -0
  14. data/lib/clio_client/api/contact.rb +23 -0
  15. data/lib/clio_client/api/crudable.rb +25 -0
  16. data/lib/clio_client/api/custom_field.rb +19 -0
  17. data/lib/clio_client/api/custom_field_set.rb +19 -0
  18. data/lib/clio_client/api/document.rb +20 -0
  19. data/lib/clio_client/api/document_version.rb +29 -0
  20. data/lib/clio_client/api/findable.rb +16 -0
  21. data/lib/clio_client/api/group.rb +22 -0
  22. data/lib/clio_client/api/listable.rb +44 -0
  23. data/lib/clio_client/api/matter.rb +22 -0
  24. data/lib/clio_client/api/note.rb +22 -0
  25. data/lib/clio_client/api/practice_area.rb +22 -0
  26. data/lib/clio_client/api/relationship.rb +22 -0
  27. data/lib/clio_client/api/task.rb +22 -0
  28. data/lib/clio_client/api/timeline_event.rb +19 -0
  29. data/lib/clio_client/api/timer.rb +31 -0
  30. data/lib/clio_client/api/user.rb +31 -0
  31. data/lib/clio_client/authorization.rb +41 -0
  32. data/lib/clio_client/http.rb +92 -0
  33. data/lib/clio_client/models/account.rb +16 -0
  34. data/lib/clio_client/models/activity.rb +31 -0
  35. data/lib/clio_client/models/activity_description.rb +21 -0
  36. data/lib/clio_client/models/bill.rb +45 -0
  37. data/lib/clio_client/models/calendar.rb +19 -0
  38. data/lib/clio_client/models/calendar_entry.rb +32 -0
  39. data/lib/clio_client/models/communication.rb +34 -0
  40. data/lib/clio_client/models/company.rb +7 -0
  41. data/lib/clio_client/models/contact.rb +38 -0
  42. data/lib/clio_client/models/custom_field.rb +21 -0
  43. data/lib/clio_client/models/custom_field_set.rb +21 -0
  44. data/lib/clio_client/models/document.rb +33 -0
  45. data/lib/clio_client/models/document_version.rb +26 -0
  46. data/lib/clio_client/models/email_communication.rb +8 -0
  47. data/lib/clio_client/models/expense_entry.rb +9 -0
  48. data/lib/clio_client/models/group.rb +18 -0
  49. data/lib/clio_client/models/matter.rb +45 -0
  50. data/lib/clio_client/models/note.rb +23 -0
  51. data/lib/clio_client/models/person.rb +9 -0
  52. data/lib/clio_client/models/phone_communication.rb +8 -0
  53. data/lib/clio_client/models/practice_area.rb +18 -0
  54. data/lib/clio_client/models/relationship.rb +19 -0
  55. data/lib/clio_client/models/task.rb +29 -0
  56. data/lib/clio_client/models/time_entry.rb +9 -0
  57. data/lib/clio_client/models/timeline_event.rb +25 -0
  58. data/lib/clio_client/models/timer.rb +28 -0
  59. data/lib/clio_client/models/user.rb +28 -0
  60. data/lib/clio_client/resource.rb +183 -0
  61. data/lib/clio_client/session.rb +56 -0
  62. data/lib/clio_client/support/address.rb +16 -0
  63. data/lib/clio_client/support/custom_field_checkbox_value.rb +7 -0
  64. data/lib/clio_client/support/custom_field_contact_value.rb +10 -0
  65. data/lib/clio_client/support/custom_field_currency_value.rb +7 -0
  66. data/lib/clio_client/support/custom_field_date_value.rb +7 -0
  67. data/lib/clio_client/support/custom_field_email_value.rb +7 -0
  68. data/lib/clio_client/support/custom_field_matter_value.rb +9 -0
  69. data/lib/clio_client/support/custom_field_numeric_value.rb +7 -0
  70. data/lib/clio_client/support/custom_field_picklist_option.rb +13 -0
  71. data/lib/clio_client/support/custom_field_picklist_value.rb +9 -0
  72. data/lib/clio_client/support/custom_field_text_area_value.rb +7 -0
  73. data/lib/clio_client/support/custom_field_text_line_value.rb +7 -0
  74. data/lib/clio_client/support/custom_field_time_value.rb +7 -0
  75. data/lib/clio_client/support/custom_field_url_value.rb +7 -0
  76. data/lib/clio_client/support/custom_field_value.rb +13 -0
  77. data/lib/clio_client/support/email_address.rb +12 -0
  78. data/lib/clio_client/support/instant_messenger.rb +12 -0
  79. data/lib/clio_client/support/phone_number.rb +13 -0
  80. data/lib/clio_client/support/rate.rb +16 -0
  81. data/lib/clio_client/support/reminder.rb +11 -0
  82. data/lib/clio_client/support/web_site.rb +12 -0
  83. data/lib/clio_client/version.rb +3 -0
  84. data/lib/clio_client.rb +107 -0
  85. data/spec/api/crudable_spec.rb +54 -0
  86. data/spec/api/findable_spec.rb +25 -0
  87. data/spec/api/listable_spec.rb +27 -0
  88. data/spec/features/activities_spec.rb +35 -0
  89. data/spec/models/account_spec.rb +12 -0
  90. data/spec/models/activity_description_spec.rb +47 -0
  91. data/spec/models/activity_spec.rb +29 -0
  92. data/spec/models/bill_spec.rb +63 -0
  93. data/spec/models/calendar_entry_spec.rb +62 -0
  94. data/spec/models/calendar_spec.rb +20 -0
  95. data/spec/models/communication_spec.rb +39 -0
  96. data/spec/models/company_spec.rb +5 -0
  97. data/spec/models/contact_spec.rb +5 -0
  98. data/spec/models/custom_field_set_spec.rb +5 -0
  99. data/spec/models/custom_field_spec.rb +5 -0
  100. data/spec/models/document_spec.rb +5 -0
  101. data/spec/models/document_version_spec.rb +6 -0
  102. data/spec/models/email_communication_spec.rb +6 -0
  103. data/spec/models/expense_entry_spec.rb +5 -0
  104. data/spec/models/group_spec.rb +5 -0
  105. data/spec/models/matter_spec.rb +5 -0
  106. data/spec/models/note_spec.rb +5 -0
  107. data/spec/models/person_spec.rb +5 -0
  108. data/spec/models/phone_communication_spec.rb +5 -0
  109. data/spec/models/practice_area_spec.rb +5 -0
  110. data/spec/models/relationship_spec.rb +5 -0
  111. data/spec/models/resource_spec.rb +116 -0
  112. data/spec/models/task_spec.rb +5 -0
  113. data/spec/models/time_entry_spec.rb +41 -0
  114. data/spec/models/timeline_event_spec.rb +6 -0
  115. data/spec/models/timer_spec.rb +6 -0
  116. data/spec/models/user_spec.rb +5 -0
  117. data/spec/spec_helper.rb +25 -0
  118. data/spec/support/associated_resource.rb +6 -0
  119. data/spec/support/dummy_endpoint.rb +11 -0
  120. data/spec/support/inherited_resource.rb +2 -0
  121. data/spec/support/resource_examples.rb +82 -0
  122. data/spec/support/test_resource.rb +11 -0
  123. metadata +286 -0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clio_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kyle d'Oliveira
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # ClioClient
2
+
3
+ This is an API client for Clio V2.
4
+
5
+ As we are all aware, the importance of API-level developments is paramount in the cloud-based software industry. Clio’s open API allows you to create valuable add-ons for your clients, and in turn, construct profitable revenue streams for your business.
6
+
7
+ Please direct any inquiries to the appropriate channel:
8
+
9
+ For technical inquiries: api@goclio.com
10
+ For business and partnership inquiries: api.partnerships@goclio.com
11
+ A community driven Clio Developers Google Group also exists where you can connect and ask questions from other Clio API users. For more information visit https://groups.google.com/forum/?fromgroups=#!forum/clio-developers.
12
+
13
+ We look forward to seeing your developments and creating successful relationships!
14
+
15
+ More information about the API can be found at http://api-docs.goclio.com/v2/index.html
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'clio_client'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install clio_client
30
+
31
+ ## Usage
32
+
33
+ You will need to do a few things before you can get started with Clio and the API. For convience, this information is pulled directly from Clio's API documentation at the top.
34
+
35
+
36
+ ### Create a Clio Account
37
+
38
+ 1. Visit http://www.goclio.com/signup/ and create an account.
39
+ 2. If you are only using your account to develop and test applications, contact api@goclio.com with your login email and we’ll set your account as a developer.
40
+
41
+ ### Create a Clio Application
42
+
43
+ 1. Login to your new Clio account at https://app.goclio.com/session/new
44
+ 2. Visit our developer portal at https://app.goclio.com/settings/developer_applications
45
+ 3. Click the Add button to create a new application. Enter details about your application here - these details will be shown to Clio users when they’re asked to authorize your application
46
+ 4. Make note of the key and the secret, as these will be used to authorize your application with Clio
47
+
48
+ Now that you have the your key and secret we can begin working. The Key will correspond to `client_id` and the secret will correspond to `client_secret`
49
+
50
+ To get the access token, you can use the client to generate the authorize url to redirect the user.
51
+
52
+ ```
53
+ client = ClioClient::Session.new({client_id: client_id, client_secret: client_secret})
54
+ client.authorize_url("http://mysite.com")
55
+ => https://app.goclio.com/oauth/authorize?response_type=code&client_id=xxxxxxxx&redirect_uri=http%3A%2F%2Fmysite.com
56
+ ```
57
+ Once the authorization has been granted Clio will redirect back to, in this example, `http://mysite.com` with the authorization code in a params `code`
58
+
59
+ ```
60
+ client.authorize_with_code "http://mysite.com", code
61
+ => {"access_token"=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "token_type"=>"bearer"}
62
+ client.authorized?
63
+ => true
64
+ ```
65
+
66
+ At this point the client is ready to use. You will need to save the `access_token` for future use.
67
+
68
+ There are many different end points you can now interact with. They all act mostly the same.
69
+
70
+ The end points available are on the ClioClient::Session
71
+ ```
72
+ activities
73
+ activity_descriptions
74
+ bills
75
+ calendar_entries
76
+ calendars
77
+ communications
78
+ contacts
79
+ custom_field_sets
80
+ custom_fields
81
+ document_versions
82
+ documents
83
+ groups
84
+ matters
85
+ notes
86
+ practice_areas
87
+ relationships
88
+ tasks
89
+ timeline_events
90
+ timer
91
+ users
92
+ ```
93
+
94
+
95
+
96
+ #### For endpoints that can "Get all X"
97
+
98
+ ```
99
+ time_entry = client.activities.first(type: 'TimeEntry')
100
+ => #<ClioClient::TimeEntry id: 12059966, created_at: #<DateTime: 2012-04-25T16:16:31+00:00 ((2456043j,58591s,0n),+0s,2299161j)>, updated_at: #<DateTime: 2013-12-14T18:52:45+00:00 ((2456641j,67965s,0n),+0s,2299161j)>, type: "TimeEntry", date: #<Date: 2012-04-25 ((2456043j,0s,0n),+0s,2299161j)>, quantity: 3600.0, price: 10.0, total: "10.0", note: "Do something", billed: false, user_id: 344053630>
101
+ client.activities.list(type: 'TimeEntry').first == time_entry
102
+ => true
103
+
104
+ ```
105
+
106
+ The amount of data returned is limited, so we can iterate over all of the results. The last query is saved and the next page of results can be accessed like this
107
+ ```
108
+ time_entries = client.activities.list(type: 'TimeEntry')
109
+ begin
110
+ do_stuff(time_entries)
111
+ time_entries = client.activities.next_page
112
+ end while time_entries.count > 0
113
+ ```
114
+
115
+ #### For endpoints that can 'Get a X' there is a `find` method
116
+ ```
117
+ time_entry = client.activities.find(12059966)
118
+ => #<ClioClient::TimeEntry id: 12059966, created_at: #<DateTime: 2012-04-25T16:16:31+00:00 ((2456043j,58591s,0n),+0s,2299161j)>, updated_at: #<DateTime: 2013-12-14T18:52:45+00:00 ((2456641j,67965s,0n),+0s,2299161j)>, type: "TimeEntry", date: #<Date: 2012-04-25 ((2456043j,0s,0n),+0s,2299161j)>, quantity: 3600.0, price: 10.0, total: "10.0", note: "Do something", billed: false, user_id: 344053630>
119
+ ```
120
+
121
+ If we can find an object we can also reload an object to get the current state of the object. This is useful for association on object that return a minimum amount of information
122
+ ```
123
+ time_entry = client.activities.find(12059966)
124
+ time_entry.user
125
+ => #<ClioClient::User id: 344053630, name: "Foo Bar">
126
+
127
+ time_entry.user.reload
128
+ => #<ClioClient::User id: 344053630, created_at: #<DateTime: 2012-04-25T15:33:34+00:00 ((2456043j,56014s,0n),+0s,2299161j)>, updated_at: #<DateTime: 2014-01-14T00:30:14+00:00 ((2456672j,1814s,0n),+0s,2299161j)>, subscription_plan: "Attorneys", time_zone: "Indiana (East)", first_name: "Foo", last_name: "Bar", email: "foo@bar.com", enabled: false>
129
+
130
+ ```
131
+
132
+ #### For endpoints that have CRUD actions
133
+
134
+ We can create a new object via
135
+ ```
136
+ time_entry = client.activities.new('type' => 'TimeEntry', 'date' => Date.today)
137
+ => #<ClioClient::TimeEntry type: "TimeEntry", date: #<Date: 2014-01-21 ((2456679j,0s,0n),+0s,2299161j)>>
138
+ ```
139
+
140
+ You can save it with
141
+ ```
142
+ time_entry = client.activities.new('type' => 'TimeEntry', 'date' => Date.today)
143
+ => #<ClioClient::TimeEntry type: "TimeEntry", date: #<Date: 2014-01-21 ((2456679j,0s,0n),+0s,2299161j)>>
144
+ time_entry.save
145
+ => #<ClioClient::TimeEntry id: 51171062, type: "TimeEntry", date: #<Date: 2014-01-21 ((2456679j,0s,0n),+0s,2299161j)>>
146
+
147
+ ```
148
+
149
+ To update, you can use the same `save` method.
150
+
151
+ To destroy an object you can do
152
+ ```
153
+ time_entry = client.activities.find(51171062)
154
+ => #<ClioClient::TimeEntry id: 51171062, created_at: #<DateTime: 2014-01-22T05:10:50+00:00 ((2456680j,18650s,0n),+0s,2299161j)>, updated_at: #<DateTime: 2014-01-22T05:10:50+00:00 ((2456680j,18650s,0n),+0s,2299161j)>, type: "TimeEntry", date: #<Date: 2014-01-21 ((2456679j,0s,0n),+0s,2299161j)>, quantity: 0.0, price: 0.0, total: "0.0", billed: false, user_id: 344053630>
155
+ time_entry.destroy
156
+ => nil
157
+ ```
158
+
159
+
160
+
161
+
162
+
163
+ ## Contributing
164
+
165
+ 1. Fork it
166
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
167
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
168
+ 4. Push to the branch (`git push origin my-new-feature`)
169
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ desc "Open an irb session preloaded with this library"
7
+ task :console do
8
+ sh "irb -rubygems -I lib -r clio_client.rb"
9
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clio_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clio_client"
8
+ spec.version = ClioClient::VERSION
9
+ spec.authors = ["Kyle d'Oliveira"]
10
+ spec.email = ["kyle@goclio.com"]
11
+ spec.description = "Api client for Clio"
12
+ spec.summary = "A simple ruby library to interact with Clio's Api"
13
+ spec.homepage = "https://github.com/doliveirakn/clio_client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "debugger"
24
+ spec.add_development_dependency "awesome_print"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ end
@@ -0,0 +1,23 @@
1
+ module ClioClient
2
+ module Api
3
+ class Activity < Base
4
+
5
+ include ClioClient::Api::Crudable
6
+ include ClioClient::Api::Listable
7
+ include ClioClient::Api::Findable
8
+
9
+ private
10
+ def data_klass(attributes)
11
+ accepted_types = %w(TimeEntry ExpenseEntry)
12
+ if accepted_types.include? attributes["type"]
13
+ ClioClient.const_get attributes["type"].intern
14
+ end
15
+ end
16
+
17
+ def end_point_url; 'activities'; end
18
+ def plural_resource; 'activities'; end
19
+ def singular_resource; 'activity'; end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module ClioClient
2
+ module Api
3
+ class ActivityDescription < Base
4
+
5
+ include ClioClient::Api::Listable
6
+
7
+ private
8
+ def data_klass(*args)
9
+ ClioClient::ActivityDescription
10
+ end
11
+
12
+ def end_point_url; 'activity_descriptions'; end
13
+ def plural_resource; 'activity_descriptions'; end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module ClioClient
2
+ module Api
3
+ class Base
4
+
5
+ attr_accessor :session
6
+
7
+ def initialize(session)
8
+ self.session = session
9
+ end
10
+
11
+ private
12
+ def data_item(params)
13
+ data_klass(params).new(params, session)
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module ClioClient
2
+ module Api
3
+ class Bill < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+
8
+ def download(id)
9
+ session.get("#{end_point_url}/#{id}.pdf", {}, false)
10
+ end
11
+
12
+ private
13
+ def data_klass(*args)
14
+ ClioClient::Bill
15
+ end
16
+
17
+ def end_point_url; 'bills'; end
18
+ def plural_resource; 'bills'; end
19
+ def singular_resource; 'bill'; end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module ClioClient
2
+ module Api
3
+ class Calendar < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+
8
+ private
9
+ def data_klass(*args)
10
+ ClioClient::Calendar
11
+ end
12
+
13
+ def end_point_url; 'calendars'; end
14
+ def plural_resource; 'calendars'; end
15
+ def singular_resource; 'calendar'; end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module ClioClient
2
+ module Api
3
+ class CalendarEntry < Base
4
+
5
+ include ClioClient::Api::Crudable
6
+ include ClioClient::Api::Listable
7
+ include ClioClient::Api::Findable
8
+
9
+ private
10
+ def data_klass(*args)
11
+ ClioClient::CalendarEntry
12
+ end
13
+
14
+ def end_point_url; 'calendar_entries'; end
15
+ def plural_resource; 'calendar_entries'; end
16
+ def singular_resource; 'calendar_entry'; end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ module ClioClient
2
+ module Api
3
+ class Communication < Base
4
+
5
+ include ClioClient::Api::Crudable
6
+ include ClioClient::Api::Listable
7
+ include ClioClient::Api::Findable
8
+
9
+ private
10
+ def data_klass(params)
11
+ if params['type'] == 'PhoneCommunication'
12
+ ClioClient::PhoneCommunication
13
+ elsif params['type'] == 'EmailCommunication'
14
+ ClioClient::EmailCommunication
15
+ end
16
+ end
17
+
18
+ def end_point_url; 'communications'; end
19
+ def plural_resource; 'communications'; end
20
+ def singular_resource; 'communication'; end
21
+
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module ClioClient
2
+ module Api
3
+ class Contact < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+ include ClioClient::Api::Crudable
8
+
9
+ private
10
+ def data_klass(attributes)
11
+ accepted_types = %w(Person Company)
12
+ if accepted_types.include? attributes["type"]
13
+ ClioClient.const_get attributes["type"].intern
14
+ end
15
+ end
16
+
17
+ def end_point_url; 'contacts'; end
18
+ def plural_resource; 'contacts'; end
19
+ def singular_resource; 'contact'; end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module ClioClient
2
+ module Api
3
+ module Crudable
4
+
5
+ def new(params = {})
6
+ data_item(params)
7
+ end
8
+
9
+ def create(params = {})
10
+ response = session.post(end_point_url, {singular_resource => params}.to_json)
11
+ data_item(response[singular_resource])
12
+ end
13
+
14
+ def update(id, params = {})
15
+ response = session.put("#{end_point_url}/#{id}", {singular_resource => params}.to_json)
16
+ data_item(response[singular_resource])
17
+ end
18
+
19
+ def destroy(id)
20
+ session.delete("#{end_point_url}/#{id}", false)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module ClioClient
2
+ module Api
3
+ class CustomField < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+
8
+ private
9
+ def data_klass(*args)
10
+ ClioClient::CustomField
11
+ end
12
+
13
+ def end_point_url; 'custom_fields'; end
14
+ def plural_resource; 'custom_fields'; end
15
+ def singular_resource; 'custom_field'; end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module ClioClient
2
+ module Api
3
+ class CustomFieldSet < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+
8
+ private
9
+ def data_klass(*args)
10
+ ClioClient::CustomFieldSet
11
+ end
12
+
13
+ def end_point_url; 'custom_field_sets'; end
14
+ def plural_resource; 'custom_field_sets'; end
15
+ def singular_resource; 'custom_field_set'; end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module ClioClient
2
+ module Api
3
+ class Document < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+ include ClioClient::Api::Crudable
8
+
9
+ private
10
+ def data_klass(*args)
11
+ ClioClient::Document
12
+ end
13
+
14
+ def end_point_url; 'documents'; end
15
+ def plural_resource; 'documents'; end
16
+ def singular_resource; 'document'; end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module ClioClient
2
+ module Api
3
+ class DocumentVersion < Base
4
+
5
+ attr_accessor :document_id
6
+
7
+ include ClioClient::Api::Crudable
8
+
9
+ def download(id)
10
+ session.get("#{end_point_url}/#{id}/download")
11
+ end
12
+
13
+ private
14
+ def data_item(params)
15
+ params["document_id"] = document_id
16
+ super(params)
17
+ end
18
+
19
+ def data_klass(*args)
20
+ ClioClient::DocumentVersion
21
+ end
22
+
23
+ def end_point_url; "documents/#{document_id}/document_versions"; end
24
+ def plural_resource; 'document_versions'; end
25
+ def singular_resource; 'document_version'; end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ module ClioClient
2
+ module Api
3
+ module Findable
4
+
5
+ def find(id)
6
+ begin
7
+ response = session.get("#{end_point_url}/#{id}")
8
+ data_item(response[singular_resource])
9
+ rescue ClioClient::ResourceNotFound
10
+ nil
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module ClioClient
2
+ module Api
3
+ class Group < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+ include ClioClient::Api::Crudable
8
+
9
+
10
+ private
11
+
12
+ def data_klass(*args)
13
+ ClioClient::Group
14
+ end
15
+
16
+ def end_point_url; 'groups'; end
17
+ def plural_resource; 'groups'; end
18
+ def singular_resource; 'group'; end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,44 @@
1
+ module ClioClient
2
+ module Api
3
+
4
+ module Listable
5
+
6
+ def first(params = {})
7
+ params[:limit] = 1
8
+ list(params).first
9
+ end
10
+
11
+ def list(params = {})
12
+ response = session.get(end_point_url, params)
13
+ @pagination_details = {last_query: params, records: 0, next_offset: response["next_offset"],
14
+ total_records: response["total_records"]
15
+ }
16
+ @pagination_details[:records] += response["records"] || 0
17
+ response[plural_resource].collect{ |r| data_item(r) }
18
+ end
19
+
20
+ def next_page
21
+ if more_pages?
22
+ params = @pagination_details[:last_query].merge(:offset => @pagination_details[:next_offset])
23
+ response = session.get(end_point_url, params)
24
+ @pagination_details[:next_offset] = response["next_offset"]
25
+ @pagination_details[:records] += response["records"] || 0
26
+ response[plural_resource].collect{ |r| data_item(r) }
27
+ else
28
+ @pagination_details = nil
29
+ []
30
+ end
31
+ end
32
+
33
+ private
34
+ def more_pages?
35
+ if @pagination_details
36
+ @pagination_details[:records] < @pagination_details[:total_records]
37
+ end
38
+ end
39
+
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ module ClioClient
2
+ module Api
3
+ class Matter < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+ include ClioClient::Api::Crudable
8
+
9
+
10
+ private
11
+
12
+ def data_klass(*args)
13
+ ClioClient::Matter
14
+ end
15
+
16
+ def end_point_url; 'matters'; end
17
+ def plural_resource; 'matters'; end
18
+ def singular_resource; 'matter'; end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module ClioClient
2
+ module Api
3
+ class Note < Base
4
+
5
+ include ClioClient::Api::Listable
6
+ include ClioClient::Api::Findable
7
+ include ClioClient::Api::Crudable
8
+
9
+
10
+ private
11
+
12
+ def data_klass(*args)
13
+ ClioClient::Note
14
+ end
15
+
16
+ def end_point_url; 'notes'; end
17
+ def plural_resource; 'notes'; end
18
+ def singular_resource; 'note'; end
19
+
20
+ end
21
+ end
22
+ end