podio 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +9 -2
  4. data/README.md +1 -4
  5. data/examples/oauth_web_flow/Gemfile +4 -0
  6. data/examples/{sinatra.rb → oauth_web_flow/sinatra.rb} +7 -6
  7. data/lib/podio.rb +18 -3
  8. data/lib/podio/active_podio/base.rb +107 -62
  9. data/lib/podio/client.rb +30 -5
  10. data/lib/podio/error.rb +22 -10
  11. data/lib/podio/middleware/error_response.rb +23 -16
  12. data/lib/podio/middleware/json_response.rb +1 -1
  13. data/lib/podio/middleware/logger.rb +3 -0
  14. data/lib/podio/middleware/oauth2.rb +3 -0
  15. data/lib/podio/models/account_provider.rb +1 -0
  16. data/lib/podio/models/action.rb +19 -2
  17. data/lib/podio/models/activation_status.rb +8 -2
  18. data/lib/podio/models/app_store_category.rb +4 -1
  19. data/lib/podio/models/app_store_share.rb +29 -16
  20. data/lib/podio/models/application.rb +57 -2
  21. data/lib/podio/models/application_email.rb +5 -2
  22. data/lib/podio/models/application_field.rb +5 -2
  23. data/lib/podio/models/batch.rb +8 -0
  24. data/lib/podio/models/by_line.rb +2 -1
  25. data/lib/podio/models/calendar_event.rb +63 -3
  26. data/lib/podio/models/calendar_mute.rb +6 -1
  27. data/lib/podio/models/category.rb +1 -0
  28. data/lib/podio/models/comment.rb +29 -8
  29. data/lib/podio/models/condition.rb +8 -0
  30. data/lib/podio/models/condition_set.rb +40 -0
  31. data/lib/podio/models/contact.rb +13 -2
  32. data/lib/podio/models/contract.rb +85 -1
  33. data/lib/podio/models/contract_event.rb +17 -0
  34. data/lib/podio/models/contract_price.rb +3 -7
  35. data/lib/podio/models/contract_price_v2.rb +31 -0
  36. data/lib/podio/models/contract_user.rb +4 -0
  37. data/lib/podio/models/conversation.rb +114 -13
  38. data/lib/podio/models/conversation_event.rb +51 -0
  39. data/lib/podio/models/conversation_message.rb +2 -1
  40. data/lib/podio/models/conversation_participant.rb +3 -2
  41. data/lib/podio/models/date_election.rb +35 -0
  42. data/lib/podio/models/email_contact.rb +46 -0
  43. data/lib/podio/models/email_subscription_setting.rb +4 -23
  44. data/lib/podio/models/embed.rb +4 -4
  45. data/lib/podio/models/experiment.rb +71 -0
  46. data/lib/podio/models/external_file.rb +7 -2
  47. data/lib/podio/models/file_attachment.rb +23 -0
  48. data/lib/podio/models/form.rb +7 -0
  49. data/lib/podio/models/friend.rb +12 -0
  50. data/lib/podio/models/grant.rb +73 -0
  51. data/lib/podio/models/hook.rb +13 -6
  52. data/lib/podio/models/importer.rb +3 -0
  53. data/lib/podio/models/integration.rb +17 -6
  54. data/lib/podio/models/invoice.rb +30 -0
  55. data/lib/podio/models/item.rb +81 -14
  56. data/lib/podio/models/item_diff.rb +9 -5
  57. data/lib/podio/models/item_field.rb +11 -2
  58. data/lib/podio/models/item_revision.rb +5 -2
  59. data/lib/podio/models/linked_account.rb +1 -0
  60. data/lib/podio/models/live.rb +61 -0
  61. data/lib/podio/models/net_promoter_score.rb +28 -0
  62. data/lib/podio/models/notification.rb +9 -4
  63. data/lib/podio/models/notification_group.rb +5 -2
  64. data/lib/podio/models/o_auth.rb +4 -2
  65. data/lib/podio/models/o_auth_client.rb +1 -2
  66. data/lib/podio/models/organization.rb +22 -10
  67. data/lib/podio/models/organization_contact.rb +2 -1
  68. data/lib/podio/models/organization_member.rb +17 -3
  69. data/lib/podio/models/organization_profile.rb +8 -2
  70. data/lib/podio/models/pin.rb +27 -0
  71. data/lib/podio/models/profile.rb +19 -50
  72. data/lib/podio/models/promotion.rb +91 -0
  73. data/lib/podio/models/rating.rb +23 -5
  74. data/lib/podio/models/recurrence.rb +6 -3
  75. data/lib/podio/models/reference.rb +17 -1
  76. data/lib/podio/models/reminder.rb +8 -3
  77. data/lib/podio/models/search.rb +7 -1
  78. data/lib/podio/models/space.rb +41 -2
  79. data/lib/podio/models/space_contact.rb +1 -2
  80. data/lib/podio/models/space_invitation.rb +4 -5
  81. data/lib/podio/models/space_member.rb +37 -4
  82. data/lib/podio/models/status.rb +20 -8
  83. data/lib/podio/models/stream_activity_group.rb +40 -0
  84. data/lib/podio/models/stream_mute.rb +7 -8
  85. data/lib/podio/models/stream_object.rb +19 -11
  86. data/lib/podio/models/subscription.rb +7 -1
  87. data/lib/podio/models/tag.rb +6 -1
  88. data/lib/podio/models/tag_search.rb +2 -1
  89. data/lib/podio/models/task.rb +74 -18
  90. data/lib/podio/models/task_label.rb +10 -2
  91. data/lib/podio/models/user.rb +50 -6
  92. data/lib/podio/models/user_mail.rb +4 -0
  93. data/lib/podio/models/user_status.rb +7 -0
  94. data/lib/podio/models/view.rb +27 -7
  95. data/lib/podio/models/widget.rb +25 -3
  96. data/lib/podio/version.rb +1 -1
  97. data/podio.gemspec +13 -10
  98. data/script/config.example.rb +6 -0
  99. data/script/referenceGenerator.rb +87 -0
  100. data/test/active_podio_test.rb +44 -34
  101. data/test/client_test.rb +13 -2
  102. metadata +89 -36
  103. data/lib/podio/middleware/date_conversion.rb +0 -37
  104. data/lib/podio/models/bulletin.rb +0 -60
  105. data/lib/podio/models/connection.rb +0 -53
  106. data/lib/podio/models/news.rb +0 -85
@@ -1,22 +1,25 @@
1
+ # @see https://developers.podio.com/doc/email
1
2
  class Podio::ApplicationEmail < ActivePodio::Base
2
3
  include ActivePodio::Updatable
3
4
 
4
5
  property :attachments, :boolean
5
- property :mappings, :hash
6
+ property :mappings, :hash
6
7
 
7
8
  class << self
9
+ # @see https://developers.podio.com/doc/email/get-app-email-configuration-622338
8
10
  def get_app_configuration(app_id)
9
11
  member Podio.connection.get { |req|
10
12
  req.url("/email/app/#{app_id}", {})
11
13
  }.body
12
14
  end
13
15
 
16
+ # @see https://developers.podio.com/doc/email/update-app-email-configuration-622851
14
17
  def update_app_configuration(app_id, options)
15
18
  Podio.connection.put { |req|
16
19
  req.url "/email/app/#{app_id}"
17
20
  req.body = options
18
21
  }.body
19
22
  end
20
-
23
+
21
24
  end
22
25
  end
@@ -1,15 +1,18 @@
1
+ # @see https://developers.podio.com/doc/applications
1
2
  class Podio::ApplicationField < ActivePodio::Base
2
3
  property :field_id, :integer
3
4
  property :type, :string
4
5
  property :external_id, :string
5
6
  property :config, :hash
6
7
  property :status, :string
8
+ property :label, :string
7
9
 
8
10
  alias_method :id, :field_id
9
- delegate_to_hash :config, :label, :description, :delta, :settings, :required?, :visible?
10
- delegate_to_hash :settings, :allowed_values, :referenceable_types, :allowed_currencies, :allowed_mimetypes, :valid_types, :options, :multiple
11
+ delegate_to_hash :config, :description, :delta, :settings, :required?, :visible?
12
+ delegate_to_hash :settings, :allowed_values, :referenceable_types, :allowed_currencies, :allowed_mimetypes, :options, :multiple
11
13
 
12
14
  class << self
15
+ # @see https://developers.podio.com/doc/applications/get-app-field-22353
13
16
  def find(app_id, field_id)
14
17
  member Podio.connection.get("/app/#{app_id}/field/#{field_id}").body
15
18
  end
@@ -1,3 +1,4 @@
1
+ # @see https://developers.podio.com/doc/batch
1
2
  class Podio::Batch < ActivePodio::Base
2
3
  property :batch_id, :integer
3
4
  property :name, :string
@@ -17,15 +18,22 @@ class Podio::Batch < ActivePodio::Base
17
18
  alias_method :id, :batch_id
18
19
 
19
20
  class << self
21
+ # @see https://developers.podio.com/doc/batch/get-batch-6144225
20
22
  def find(id)
21
23
  member Podio.connection.get("/batch/#{id}").body
22
24
  end
23
25
 
26
+ # @see https://developers.podio.com/doc/batch/get-batches-6078877
24
27
  def find_all(options={})
25
28
  list Podio.connection.get { |req|
26
29
  req.url("/batch/", options)
27
30
  }.body
28
31
  end
32
+
33
+ # @see https://developers.podio.com/doc/batch/get-running-batches-15856178
34
+ def find_running(ref_type, ref_id, plugin)
35
+ list Podio.connection.get("/batch/#{ref_type}/#{ref_id}/#{plugin}/running/").body
36
+ end
29
37
  end
30
38
 
31
39
  end
@@ -8,4 +8,5 @@ class Podio::ByLine < ActivePodio::Base
8
8
  property :name, :string
9
9
  property :url, :string
10
10
  property :avatar, :integer # Sometimes used by older operations
11
- end
11
+ property :last_seen_on, :datetime
12
+ end
@@ -1,45 +1,98 @@
1
+ # @see https://developers.podio.com/doc/calendar
1
2
  class Podio::CalendarEvent < ActivePodio::Base
2
- property :type, :string
3
- property :id, :integer
4
- property :group, :string
3
+ property :uid, :string
4
+ property :ref_type, :string
5
+ property :ref_id, :integer
5
6
  property :title, :string
6
7
  property :description, :string
7
8
  property :location, :string
8
9
  property :status, :string
9
10
  property :start, :datetime, :convert_timezone => false
11
+ property :start_utc, :datetime, :convert_timezone => false
10
12
  property :start_date, :date
11
13
  property :start_time, :string
12
14
  property :end, :datetime, :convert_timezone => false
15
+ property :end_utc, :datetime, :convert_timezone => false
13
16
  property :end_date, :date
14
17
  property :end_time, :string
15
18
  property :link, :string
19
+ property :app, :hash
20
+ property :source, :string
21
+
22
+ alias_method :id, :uid
16
23
 
17
24
  class << self
18
25
 
26
+ # @see https://developers.podio.com/doc/calendar/get-global-calendar-22458
19
27
  def find_all(options = {})
20
28
  list Podio.connection.get { |req|
21
29
  req.url('/calendar/', options)
22
30
  }.body
23
31
  end
24
32
 
33
+ def find_all_for_linked_account(linked_account_id, options = {})
34
+ list Podio.connection.get { |req|
35
+ req.url("/calendar/linked_account/#{linked_account_id}/", options)
36
+ }.body
37
+ end
38
+
39
+ # @see https://developers.podio.com/doc/calendar/get-space-calendar-22459
25
40
  def find_all_for_space(space_id, options={})
26
41
  list Podio.connection.get { |req|
27
42
  req.url("/calendar/space/#{space_id}/", options)
28
43
  }.body
29
44
  end
30
45
 
46
+ # @see https://developers.podio.com/doc/calendar/get-app-calendar-22460
31
47
  def find_all_for_app(app_id, options={})
32
48
  list Podio.connection.get { |req|
33
49
  req.url("/calendar/app/#{app_id}/", options)
34
50
  }.body
35
51
  end
36
52
 
53
+ # @see
54
+ def move_event(uid, attributes={})
55
+ response = Podio.connection.post do |req|
56
+ req.url "/calendar/event/#{uid}/move"
57
+ req.body = attributes
58
+ end
59
+ member response.body
60
+ end
61
+
62
+ # @see
63
+ def move_event_external(linked_account_id, uid, attributes={})
64
+ response = Podio.connection.post do |req|
65
+ req.url "/calendar/linked_account/#{linked_account_id}/event/#{CGI.escape(uid)}/move"
66
+ req.body = attributes
67
+ end
68
+ member response.body
69
+ end
70
+
71
+ # @see
72
+ def update_event_duration(uid, attributes={})
73
+ response = Podio.connection.put do |req|
74
+ req.url "/calendar/event/#{uid}/duration"
75
+ req.body = attributes
76
+ end
77
+ member response.body
78
+ end
79
+
80
+ # @see
81
+ def update_event_duration_external(linked_account_id, uid, attributes={})
82
+ response = Podio.connection.put do |req|
83
+ req.url "/calendar/linked_account/#{linked_account_id}/event/#{CGI.escape(uid)}/duration"
84
+ req.body = attributes
85
+ end
86
+ member response.body
87
+ end
88
+
37
89
  def get_calendars_for_linked_acc(acc_id, options={})
38
90
  list Podio.connection.get { |req|
39
91
  req.url("/calendar/export/linked_account/#{acc_id}/available", options)
40
92
  }.body
41
93
  end
42
94
 
95
+ # @see https://developers.podio.com/doc/calendar/get-calendar-summary-1609256
43
96
  def find_summary(options = {})
44
97
  response = Podio.connection.get do |req|
45
98
  req.url("/calendar/summary", options)
@@ -49,6 +102,7 @@ class Podio::CalendarEvent < ActivePodio::Base
49
102
  response
50
103
  end
51
104
 
105
+ # @see https://developers.podio.com/doc/calendar/get-calendar-summary-for-space-1609328
52
106
  def find_summary_for_space(space_id)
53
107
  response = Podio.connection.get("/calendar/space/#{space_id}/summary").body
54
108
  response['today']['events'] = list(response['today']['events'])
@@ -63,6 +117,7 @@ class Podio::CalendarEvent < ActivePodio::Base
63
117
  response
64
118
  end
65
119
 
120
+ # @see https://developers.podio.com/doc/calendar/get-calendar-summary-for-personal-1657903
66
121
  def find_personal_summary
67
122
  response = Podio.connection.get("/calendar/personal/summary").body
68
123
  response['today']['events'] = list(response['today']['events'])
@@ -70,6 +125,7 @@ class Podio::CalendarEvent < ActivePodio::Base
70
125
  response
71
126
  end
72
127
 
128
+ # @see https://developers.podio.com/doc/calendar/set-reference-export-9183515
73
129
  def set_reference_export(linked_account_id, ref_type, ref_id, attributes={})
74
130
  response = Podio.connection.put do |req|
75
131
  req.url "/calendar/export/linked_account/#{linked_account_id}/#{ref_type}/#{ref_id}"
@@ -78,16 +134,19 @@ class Podio::CalendarEvent < ActivePodio::Base
78
134
  response.status
79
135
  end
80
136
 
137
+ # @see https://developers.podio.com/doc/calendar/get-exports-by-reference-7554180
81
138
  def get_reference_exports(ref_type, ref_id)
82
139
  list Podio.connection.get { |req|
83
140
  req.url("/calendar/export/#{ref_type}/#{ref_id}/")
84
141
  }.body
85
142
  end
86
143
 
144
+ # @see https://developers.podio.com/doc/calendar/stop-reference-export-9183590
87
145
  def stop_reference_export(linked_account_id, ref_type, ref_id)
88
146
  Podio.connection.delete("/calendar/export/linked_account/#{linked_account_id}/#{ref_type}/#{ref_id}").status
89
147
  end
90
148
 
149
+ # @see https://developers.podio.com/doc/calendar/get-global-export-9381099
91
150
  def set_global_export(linked_account_id, attributes={})
92
151
  response = Podio.connection.put do |req|
93
152
  req.url "/calendar/export/linked_account/#{linked_account_id}"
@@ -96,6 +155,7 @@ class Podio::CalendarEvent < ActivePodio::Base
96
155
  response.status
97
156
  end
98
157
 
158
+ # @see https://developers.podio.com/doc/calendar/get-global-exports-7554169
99
159
  def get_global_exports()
100
160
  list Podio.connection.get { |req|
101
161
  req.url("/calendar/export/")
@@ -1,3 +1,4 @@
1
+ # @see https://developers.podio.com/doc/calendar
1
2
  class Podio::CalendarMute < ActivePodio::Base
2
3
  property :id, :integer
3
4
  property :type, :string
@@ -8,16 +9,20 @@ class Podio::CalendarMute < ActivePodio::Base
8
9
  property :task, :boolean
9
10
 
10
11
  class << self
12
+
13
+ # @see https://developers.podio.com/doc/calendar/get-mutes-in-global-calendar-62730
11
14
  def find_all
12
15
  list Podio.connection.get('/calendar/mute/').body
13
16
  end
14
17
 
18
+ # @see https://developers.podio.com/doc/calendar/mute-objects-from-global-calendar-79418
15
19
  def create(scope_type, scope_id, object_type = nil)
16
20
  path = "/calendar/mute/#{scope_type}/#{scope_id}/"
17
21
  path += "#{object_type}/" unless object_type.nil?
18
- Podio.connection.post(path).status
22
+ Podio.connection.post(path).status
19
23
  end
20
24
 
25
+ # @see https://developers.podio.com/doc/calendar/unmute-objects-from-the-global-calendar-79420
21
26
  def delete(scope_type, scope_id, object_type = nil)
22
27
  path = "/calendar/mute/#{scope_type}/#{scope_id}/"
23
28
  path += "#{object_type}/" unless object_type.nil?
@@ -1,3 +1,4 @@
1
+ # @see https://developers.podio.com/doc/app-store
1
2
  class Podio::Category < ActivePodio::Base
2
3
  property :category_id, :integer
3
4
  property :type, :string
@@ -1,15 +1,20 @@
1
+ # @see https://developers.podio.com/doc/comments
1
2
  class Podio::Comment < ActivePodio::Base
2
3
  property :comment_id, :integer
3
4
  property :value, :string
4
5
  property :rich_value, :string
5
- property :external_id, :integer
6
+ property :external_id, :string
6
7
  property :space_id, :integer
7
8
  property :created_on, :datetime
9
+ property :like_count, :integer
10
+ property :is_liked, :boolean
8
11
  property :files, :array # when outputting comments
9
12
  property :file_ids, :array # when inputting comments
10
13
  property :embed_id, :integer #optional, when inputting comments
11
14
  property :embed_file_id, :integer #optional, when inputting comments
12
15
 
16
+ has_one :ref, :class => 'Reference'
17
+
13
18
  has_one :embed, :class => 'Embed'
14
19
  has_one :embed_file, :class => 'FileAttachment'
15
20
 
@@ -18,23 +23,31 @@ class Podio::Comment < ActivePodio::Base
18
23
  has_many :files, :class => 'FileAttachment'
19
24
  has_many :questions, :class => 'Question'
20
25
 
26
+ has_many :granted_users, :class => 'Contact' # Only set when creating new comment
27
+ has_many :invited_users, :class => 'Contact' # Only set when creating new comment
28
+
21
29
  alias_method :id, :comment_id
22
30
  attr_accessor :commentable_type, :commentable_id
23
31
 
24
- def create
25
- self.comment_id = Comment.create(commentable_type, commentable_id, attributes)
32
+ # @see https://developers.podio.com/doc/comments/add-comment-to-object-22340
33
+ def create(options={})
34
+ updated_attributes = Comment.create(self.commentable_type, self.commentable_id, self.attributes, options)
35
+ self.attributes = updated_attributes.symbolize_keys
36
+ self.initialize_attributes(self.attributes)
26
37
  end
27
-
38
+
28
39
  class << self
29
- def create(commentable_type, commentable_id, attributes)
40
+ # @see https://developers.podio.com/doc/comments/add-comment-to-object-22340
41
+ def create(commentable_type, commentable_id, attributes, options={})
30
42
  response = Podio.connection.post do |req|
31
- req.url "/comment/#{commentable_type}/#{commentable_id}"
43
+ req.url("/comment/#{commentable_type}/#{commentable_id}", options)
32
44
  req.body = attributes
33
45
  end
34
46
 
35
- response.body['comment_id']
47
+ response.body
36
48
  end
37
49
 
50
+ # @see https://developers.podio.com/doc/comments/update-a-comment-22346
38
51
  def update(id, attributes)
39
52
  response = Podio.connection.put do |req|
40
53
  req.url "/comment/#{id}"
@@ -44,14 +57,17 @@ class Podio::Comment < ActivePodio::Base
44
57
  response.status
45
58
  end
46
59
 
60
+ # @see https://developers.podio.com/doc/comments/delete-a-comment-22347
47
61
  def delete(id)
48
62
  Podio.connection.delete("/comment/#{id}").status
49
63
  end
50
64
 
65
+ # @see https://developers.podio.com/doc/comments/get-a-comment-22345
51
66
  def find(id)
52
67
  member Podio.connection.get("/comment/#{id}").body
53
68
  end
54
69
 
70
+ # @see https://developers.podio.com/doc/comments/get-comments-on-object-22371
55
71
  def find_all_for(commentable_type, commentable_id)
56
72
  list Podio.connection.get("/comment/#{commentable_type}/#{commentable_id}").body
57
73
  end
@@ -60,6 +76,11 @@ class Podio::Comment < ActivePodio::Base
60
76
  #Internal
61
77
  list Podio.connection.get("/comment/share/").body
62
78
  end
63
-
79
+
80
+ # @see https://developers.podio.com/doc/comments/get-who-liked-a-comment-29007011
81
+ def liked_by(id)
82
+ Podio.connection.get("/comment/#{id}/liked_by/").body.map{|values| Podio::Contact.new(values)}
83
+ end
84
+
64
85
  end
65
86
  end
@@ -0,0 +1,8 @@
1
+ class Podio::Condition < ActivePodio::Base
2
+ property :condition_id, :integer
3
+ property :type, :string
4
+ property :config, :hash
5
+ property :negate, :boolean
6
+
7
+ alias_method :id, :condition_id
8
+ end
@@ -0,0 +1,40 @@
1
+ class Podio::ConditionSet < ActivePodio::Base
2
+ property :condition_set_id, :integer
3
+ property :name, :string
4
+ property :description, :string
5
+
6
+ has_many :conditions, :class => 'Condition'
7
+
8
+ alias_method :id, :condition_set_id
9
+
10
+ class << self
11
+ def find_all(options={})
12
+ list Podio.connection.get { |req|
13
+ req.url("/condition_set/", options)
14
+ }.body
15
+ end
16
+
17
+ def find(condition_set_id)
18
+ member Podio.connection.get("/condition_set/#{condition_set_id}").body
19
+ end
20
+
21
+ def create(attributes)
22
+ member Podio.connection.post { |req|
23
+ req.url("/condition_set/")
24
+ req.body = attributes
25
+ }.body
26
+ end
27
+
28
+ def update(condition_set_id, attributes)
29
+ member Podio.connection.put { |req|
30
+ req.url("/condition_set/#{condition_set_id}")
31
+ req.body = attributes
32
+ }.body
33
+ end
34
+
35
+ def delete(condition_set_id)
36
+ Podio.connection.delete("/condition_set/#{condition_set_id}")
37
+ end
38
+ end
39
+
40
+ end
@@ -1,16 +1,18 @@
1
+ # @see https://developers.podio.com/doc/contacts
1
2
  class Podio::Contact < Podio::Profile
2
3
  include ActivePodio::Updatable
3
4
 
4
5
  property :user_id, :integer
5
6
  property :organization, :string
6
- property :role, :string # Only available when getting contacts for a space
7
- property :removable, :boolean # Only available when getting contacts for a space
8
7
  property :type, :string # user, space, connection - blank probably means it's a real user / Podio member
9
8
  property :space_id, :integer
10
9
  property :link, :string
11
10
  property :last_seen_on, :datetime
12
11
  property :rights, :array
12
+
13
+ # Only available for external contacts
13
14
  property :external_id, :string
15
+ property :external_picture, :string
14
16
 
15
17
  alias_method :id, :user_id
16
18
 
@@ -18,4 +20,13 @@ class Podio::Contact < Podio::Profile
18
20
  self.class.update_contact(self.profile_id, self.attributes)
19
21
  end
20
22
 
23
+ class << self
24
+ def find_external(linked_acc_id, external_contact_id)
25
+ member Podio.connection.post { |req|
26
+ req.url "/contact/linked_account/#{linked_acc_id}"
27
+ req.body = { :external_contact_id => external_contact_id }
28
+ }.body
29
+ end
30
+ end
31
+
21
32
  end
@@ -4,14 +4,18 @@ class Podio::Contract < ActivePodio::Base
4
4
  property :contract_id, :integer
5
5
  property :org_id, :integer
6
6
  property :status, :string
7
+ property :blocked, :boolean
7
8
  property :created_on, :datetime
8
9
  property :started_on, :datetime
10
+ property :created_via, :string
9
11
  property :ended_on, :datetime
10
12
  property :item_prices, :hash
11
13
  property :item_limits, :hash
12
14
  property :payment_id, :string
13
15
  property :payment_status, :string
16
+ property :payment_provider, :string
14
17
  property :accounting_id, :string
18
+ property :accounting_provider, :string
15
19
  property :full, :boolean
16
20
  property :premium_emp_network, :boolean
17
21
  property :premium_spaces, :array
@@ -24,14 +28,27 @@ class Podio::Contract < ActivePodio::Base
24
28
  property :ended_comment, :string
25
29
  property :billing_mail, :string
26
30
  property :model, :string
31
+ property :unpaid_due_date, :datetime
32
+ property :count_employee, :integer
33
+ property :count_external, :integer
34
+ property :yearly_rebate_factor, :decimal
35
+ property :mrr, :decimal
36
+ property :days_overdue, :integer
37
+ property :overdue_status, :string
27
38
 
28
39
  has_one :org, :class => 'Organization'
29
40
  has_one :user, :class => 'User'
41
+ has_one :sold_by, :class => 'User'
30
42
  has_one :price, :class => 'ContractPrice'
43
+ has_one :price_v2, :class => 'ContractPriceV2'
31
44
  has_many :premium_spaces, :class => 'Space'
32
45
 
33
46
  alias_method :id, :contract_id
34
47
 
48
+ def price_v2=(attributes)
49
+ self[:price_v2] = attributes
50
+ end
51
+
35
52
  def premium_space_ids=(values)
36
53
  self[:premium_space_ids] = (values || []).map(&:to_i)
37
54
  end
@@ -46,6 +63,12 @@ class Podio::Contract < ActivePodio::Base
46
63
  self["price"] = pricing
47
64
  end
48
65
 
66
+ def calculate_price_v2
67
+ pricing = self.class.calculate_price_v2(self.contract_id, self.attributes.slice(:full, :premium_emp_network, :premium_space_ids))
68
+ self.clear_price_v2
69
+ self["price_v2"] = pricing
70
+ end
71
+
49
72
  def create_payment(query_string)
50
73
  self.class.create_payment(self.contract_id, query_string)
51
74
  end
@@ -58,7 +81,27 @@ class Podio::Contract < ActivePodio::Base
58
81
  self.class.end(self.id, attributes)
59
82
  end
60
83
 
61
- handle_api_errors_for :update, :delete, :create_payment, :end # Call must be made after the methods to handle have been defined
84
+ def change_to_fixed
85
+ self.class.change_to_fixed(self.contract_id,
86
+ :item_limits => {
87
+ :employee => self.item_limits['employee'],
88
+ :external => self.item_limits['external']
89
+ },
90
+ :invoice_interval => self.invoice_interval
91
+ )
92
+ end
93
+
94
+ def change_to_variable
95
+ self.class.change_to_variable(self.contract_id)
96
+ end
97
+
98
+ def block
99
+ self.class.block(self.contract_id)
100
+ end
101
+
102
+ def unblock
103
+ self.class.unblock(self.contract_id)
104
+ end
62
105
 
63
106
  class << self
64
107
  def find(contract_id)
@@ -69,6 +112,10 @@ class Podio::Contract < ActivePodio::Base
69
112
  list Podio.connection.get("/contract/").body
70
113
  end
71
114
 
115
+ def find_all_my_offers
116
+ list Podio.connection.get("/contract/offered/").body
117
+ end
118
+
72
119
  def find_for_org(org_id)
73
120
  list Podio.connection.get("/contract/org/#{org_id}/").body
74
121
  end
@@ -77,6 +124,10 @@ class Podio::Contract < ActivePodio::Base
77
124
  member Podio.connection.get("/contract/org/#{org_id}/user").body
78
125
  end
79
126
 
127
+ def find_all_unpaid
128
+ list Podio.connection.get("/contract/unpaid/").body
129
+ end
130
+
80
131
  def create(attributes)
81
132
  response = Podio.connection.post do |req|
82
133
  req.url "/contract/"
@@ -116,7 +167,16 @@ class Podio::Contract < ActivePodio::Base
116
167
  req.url "/contract/#{contract_id}/price"
117
168
  req.body = attributes
118
169
  end
170
+
171
+ response.body
172
+ end
119
173
 
174
+ def calculate_price_v2(contract_id, attributes)
175
+ response = Podio.connection.post do |req|
176
+ req.url "/contract/#{contract_id}/price/v2"
177
+ req.body = attributes
178
+ end
179
+
120
180
  response.body
121
181
  end
122
182
 
@@ -128,5 +188,29 @@ class Podio::Contract < ActivePodio::Base
128
188
 
129
189
  response.body
130
190
  end
191
+
192
+ def change_to_fixed(contract_id, attributes)
193
+ response = Podio.connection.post do |req|
194
+ req.url "/contract/#{contract_id}/change_to/fixed"
195
+ req.body = attributes
196
+ end
197
+
198
+ response.status
199
+ end
200
+
201
+ def change_to_variable(contract_id)
202
+ response = Podio.connection.post("/contract/#{contract_id}/change_to/variable")
203
+ response.status
204
+ end
205
+
206
+ def block(contract_id)
207
+ response = Podio.connection.post("/contract/#{contract_id}/block")
208
+ response.status
209
+ end
210
+
211
+ def unblock(contract_id)
212
+ response = Podio.connection.post("/contract/#{contract_id}/unblock")
213
+ response.status
214
+ end
131
215
  end
132
216
  end