Class: Podio::Contract

Inherits:
ActivePodio::Base show all
Includes:
ActivePodio::Updatable
Defined in:
lib/podio/models/contract.rb

Instance Attribute Summary

Attributes inherited from ActivePodio::Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActivePodio::Updatable

#remove_nil_values, #update_attributes

Methods inherited from ActivePodio::Base

#==, #[], #[]=, #api_friendly_ref_type, #as_json, collection, delegate_to_hash, has_many, has_one, #hash, #initialize, #initialize_attributes, klass_from_string, list, member, #new_record?, output_attribute_as_json, #parent_model, #persisted?, property, #to_param

Constructor Details

This class inherits a constructor from ActivePodio::Base

Class Method Details

.block(contract_id) ⇒ Object



196
197
198
199
# File 'lib/podio/models/contract.rb', line 196

def block(contract_id)
  response = Podio.connection.post("/contract/#{contract_id}/block")
  response.status
end

.calculate_price(contract_id, attributes) ⇒ Object



164
165
166
167
168
169
170
171
# File 'lib/podio/models/contract.rb', line 164

def calculate_price(contract_id, attributes)
  response = Podio.connection.post do |req|
    req.url "/contract/#{contract_id}/price"
    req.body = attributes
  end

  response.body
end

.change_to_fixed(contract_id, attributes) ⇒ Object



182
183
184
185
186
187
188
189
# File 'lib/podio/models/contract.rb', line 182

def change_to_fixed(contract_id, attributes)
  response = Podio.connection.post do |req|
    req.url "/contract/#{contract_id}/change_to/fixed"
    req.body = attributes
  end

  response.status
end

.change_to_variable(contract_id) ⇒ Object



191
192
193
194
# File 'lib/podio/models/contract.rb', line 191

def change_to_variable(contract_id)
  response = Podio.connection.post("/contract/#{contract_id}/change_to/variable")
  response.status
end

.create(attributes) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/podio/models/contract.rb', line 130

def create(attributes)
  response = Podio.connection.post do |req|
    req.url "/contract/"
    req.body = attributes
  end

  member response.body
end

.create_payment(contract_id, query_string) ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/podio/models/contract.rb', line 173

def create_payment(contract_id, query_string)
  response = Podio.connection.post do |req|
    req.url "/contract/#{contract_id}/payment"
    req.body = {:query_string => query_string}
  end

  response.body
end

.delete(id) ⇒ Object



160
161
162
# File 'lib/podio/models/contract.rb', line 160

def delete(id)
  Podio.connection.delete("/contract/#{id}").body
end

.end(contract_id, attributes) ⇒ Object



151
152
153
154
155
156
157
158
# File 'lib/podio/models/contract.rb', line 151

def end(contract_id, attributes)
  response = Podio.connection.post do |req|
    req.url "/contract/#{contract_id}/end"
    req.body = attributes
  end

  response.body
end

.find(contract_id, options = {}) ⇒ Object



106
107
108
# File 'lib/podio/models/contract.rb', line 106

def find(contract_id, options={})
  member Podio.connection.get("/contract/#{contract_id}", options).body
end

.find_all_mineObject



110
111
112
# File 'lib/podio/models/contract.rb', line 110

def find_all_mine
  list Podio.connection.get("/contract/").body
end

.find_all_my_offersObject



114
115
116
# File 'lib/podio/models/contract.rb', line 114

def find_all_my_offers
  list Podio.connection.get("/contract/offered/").body
end

.find_all_unpaidObject



126
127
128
# File 'lib/podio/models/contract.rb', line 126

def find_all_unpaid
  list Podio.connection.get("/contract/unpaid/").body
end

.find_for_org(org_id) ⇒ Object



118
119
120
# File 'lib/podio/models/contract.rb', line 118

def find_for_org(org_id)
  list Podio.connection.get("/contract/org/#{org_id}/").body
end

.find_users_for_org(org_id) ⇒ Object



122
123
124
# File 'lib/podio/models/contract.rb', line 122

def find_users_for_org(org_id)
  member Podio.connection.get("/contract/org/#{org_id}/user").body
end

.get_list_pricesObject



210
211
212
# File 'lib/podio/models/contract.rb', line 210

def get_list_prices
  Podio.connection.get('/contract/price/').body
end

.get_tier_prices(contract_id) ⇒ Object



206
207
208
# File 'lib/podio/models/contract.rb', line 206

def get_tier_prices(contract_id)
  Podio.connection.get("/contract/#{contract_id}/price/tier").body
end

.start(contract_id) ⇒ Object



147
148
149
# File 'lib/podio/models/contract.rb', line 147

def start(contract_id)
  Podio.connection.post("/contract/#{contract_id}/start").body
end

.unblock(contract_id) ⇒ Object



201
202
203
204
# File 'lib/podio/models/contract.rb', line 201

def unblock(contract_id)
  response = Podio.connection.post("/contract/#{contract_id}/unblock")
  response.status
end

.update(contract_id, attributes) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/podio/models/contract.rb', line 139

def update(contract_id, attributes)
  response = Podio.connection.put do |req|
    req.url "/contract/#{contract_id}"
    req.body = attributes
  end
  response.status
end

Instance Method Details

#blockObject



93
94
95
# File 'lib/podio/models/contract.rb', line 93

def block
  self.class.block(self.contract_id)
end

#calculate_priceObject



61
62
63
64
65
# File 'lib/podio/models/contract.rb', line 61

def calculate_price
  pricing = self.class.calculate_price(self.contract_id, self.attributes.slice(:full, :premium_emp_network, :premium_space_ids))
  self.clear_price
  self["price"] = pricing
end

#change_to_fixedObject



79
80
81
82
83
84
85
86
87
# File 'lib/podio/models/contract.rb', line 79

def change_to_fixed
  self.class.change_to_fixed(self.contract_id,
    :item_limits => {
      :employee => self.item_limits['employee'],
      :external => self.item_limits['external']
    },
    :invoice_interval => self.invoice_interval
  )
end

#change_to_variableObject



89
90
91
# File 'lib/podio/models/contract.rb', line 89

def change_to_variable
  self.class.change_to_variable(self.contract_id)
end

#create_payment(query_string) ⇒ Object



67
68
69
# File 'lib/podio/models/contract.rb', line 67

def create_payment(query_string)
  self.class.create_payment(self.contract_id, query_string)
end

#deleteObject



71
72
73
# File 'lib/podio/models/contract.rb', line 71

def delete
  self.class.delete(self.id)
end

#end(attributes) ⇒ Object



75
76
77
# File 'lib/podio/models/contract.rb', line 75

def end(attributes)
  self.class.end(self.id, attributes)
end

#premium_space_ids=(values) ⇒ Object



53
54
55
# File 'lib/podio/models/contract.rb', line 53

def premium_space_ids=(values)
  self[:premium_space_ids] = (values || []).map(&:to_i)
end

#price=(attributes) ⇒ Object



49
50
51
# File 'lib/podio/models/contract.rb', line 49

def price=(attributes)
  self[:price] = attributes
end

#tier_pricesObject



101
102
103
# File 'lib/podio/models/contract.rb', line 101

def tier_prices
  self.class.get_tier_prices(self.contract_id)
end

#unblockObject



97
98
99
# File 'lib/podio/models/contract.rb', line 97

def unblock
  self.class.unblock(self.contract_id)
end

#updateObject



57
58
59
# File 'lib/podio/models/contract.rb', line 57

def update
  self.class.update(self.contract_id, self.attributes.except(:premium_spaces))
end