podio 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/podio.rb CHANGED
@@ -30,6 +30,13 @@ module Podio
30
30
  Thread.current[:podio_client] = new_client
31
31
  end
32
32
 
33
+ def with_client
34
+ old_client = Podio.client.dup
35
+ yield
36
+ ensure
37
+ Podio.client = old_client
38
+ end
39
+
33
40
  def connection
34
41
  client.connection
35
42
  end
@@ -50,11 +57,12 @@ module Podio
50
57
  end
51
58
  end
52
59
 
53
- class OAuthToken < Struct.new(:access_token, :refresh_token, :expires_at)
60
+ class OAuthToken < Struct.new(:access_token, :refresh_token, :expires_at, :reference, :refreshed)
54
61
  def initialize(params = {})
55
- self.access_token = params['access_token']
62
+ self.access_token = params['access_token']
56
63
  self.refresh_token = params['refresh_token']
57
- self.expires_at = Time.now + params['expires_in'] if params['expires_in']
64
+ self.reference = params['ref']
65
+ self.expires_at = Time.now + params['expires_in'] if params['expires_in']
58
66
  end
59
67
  end
60
68
 
@@ -65,22 +73,32 @@ module Podio
65
73
  autoload :Application, 'podio/areas/application'
66
74
  autoload :Bulletin, 'podio/areas/bulletin'
67
75
  autoload :Category, 'podio/areas/app_store'
76
+ autoload :AppStoreShare, 'podio/areas/app_store'
68
77
  autoload :Comment, 'podio/areas/comment'
69
78
  autoload :Connection, 'podio/areas/connection'
70
79
  autoload :Contact, 'podio/areas/contact'
71
80
  autoload :Conversation, 'podio/areas/conversation'
72
81
  autoload :File, 'podio/areas/file'
73
82
  autoload :Form, 'podio/areas/form'
83
+ autoload :Hook, 'podio/areas/hook'
74
84
  autoload :Item, 'podio/areas/item'
85
+ autoload :Importer, 'podio/areas/importer'
75
86
  autoload :Integration, 'podio/areas/integration'
87
+ autoload :Notification, 'podio/areas/notification'
88
+ autoload :NotificationGroup, 'podio/areas/notification'
89
+ autoload :OAuth, 'podio/areas/oauth'
90
+ autoload :OAuthClient, 'podio/areas/oauth'
76
91
  autoload :Organization, 'podio/areas/organization'
77
92
  autoload :OrganizationMember, 'podio/areas/organization_member'
78
93
  autoload :OrganizationProfile, 'podio/areas/organization_profile'
94
+ autoload :Rating, 'podio/areas/rating'
79
95
  autoload :Search, 'podio/areas/search'
80
96
  autoload :Space, 'podio/areas/space'
81
97
  autoload :SpaceInvite, 'podio/areas/space'
82
98
  autoload :SpaceMember, 'podio/areas/space'
83
99
  autoload :Status, 'podio/areas/status'
100
+ autoload :Subscription, 'podio/areas/subscription'
101
+ autoload :Tag, 'podio/areas/tag'
84
102
  autoload :Task, 'podio/areas/task'
85
103
  autoload :TaskLabel, 'podio/areas/task'
86
104
  autoload :User, 'podio/areas/user'
@@ -42,4 +42,28 @@ module Podio
42
42
  Struct.new(:functional, :vertical).new(functionals, verticals)
43
43
  end
44
44
  end
45
+
46
+ module AppStoreShare
47
+ include Podio::ResponseWrapper
48
+ extend self
49
+
50
+ def create(attributes)
51
+ response = Podio.connection.post do |req|
52
+ req.url "/app_store/"
53
+ req.body = attributes
54
+ end
55
+
56
+ response.body['share_id']
57
+ end
58
+
59
+ def find(id)
60
+ member Podio.connection.get("/app_store/#{id}/v2").body
61
+ end
62
+
63
+ def find_all_private_for_org(org_id)
64
+ list Podio.connection.get("/app_store/org/#{org_id}/").body['shares']
65
+ end
66
+
67
+ end
68
+
45
69
  end
@@ -8,8 +8,6 @@ module Podio
8
8
  end
9
9
 
10
10
  def find_all(options={})
11
- options.assert_valid_keys(:external_id, :space_ids, :owner_id, :status, :type)
12
-
13
11
  list Podio.connection.get { |req|
14
12
  req.url("/app/", options)
15
13
  }.body
@@ -28,6 +26,22 @@ module Podio
28
26
  end
29
27
 
30
28
  response.body
29
+ end
30
+
31
+ def create(attributes)
32
+ response = Podio.connection.post do |req|
33
+ req.url "/app/"
34
+ req.body = attributes
35
+ end
36
+ response.body['app_id']
37
+ end
38
+
39
+ def deactivate(id)
40
+ Podio.connection.post("/app/#{id}/deactivate").body
41
+ end
42
+
43
+ def delete(id)
44
+ Podio.connection.delete("/app/#{id}").body
31
45
  end
32
46
 
33
47
  end
@@ -4,7 +4,6 @@ module Podio
4
4
  extend self
5
5
 
6
6
  def all(options={})
7
- options.assert_valid_keys(:key, :value, :limit, :offset, :type, :order, :name, :email, :required, :contact_type, :exclude_self)
8
7
  options[:exclude_self] = (options[:exclude_self] == false ? "0" : "1" )
9
8
 
10
9
  list Podio.connection.get { |req|
@@ -13,8 +12,6 @@ module Podio
13
12
  end
14
13
 
15
14
  def top(options={})
16
- options.assert_valid_keys(:limit, :type)
17
-
18
15
  list Podio.connection.get { |req|
19
16
  req.url("/contact/top/", options)
20
17
  }.body
@@ -25,7 +22,6 @@ module Podio
25
22
  end
26
23
 
27
24
  def find_all_for_org(org_id, options={})
28
- options.assert_valid_keys(:key, :value, :limit, :offset, :type, :order, :name, :email, :contact_type, :exclude_self)
29
25
  options[:type] ||= 'full'
30
26
  options[:exclude_self] = (options[:exclude_self] == false ? "0" : "1" )
31
27
 
@@ -35,7 +31,6 @@ module Podio
35
31
  end
36
32
 
37
33
  def find_all_for_space(space_id, options={})
38
- options.assert_valid_keys(:key, :value, :limit, :offset, :type, :order, :name, :email, :required, :contact_type, :exclude_self)
39
34
  options[:type] ||= 'full'
40
35
  options[:exclude_self] = (options[:exclude_self] == false ? "0" : "1" )
41
36
 
@@ -45,7 +40,6 @@ module Podio
45
40
  end
46
41
 
47
42
  def find_all_for_connection(connection_id, options={})
48
- options.assert_valid_keys(:key, :value, :limit, :offset, :type, :order, :name, :email)
49
43
  options[:type] ||= 'full'
50
44
 
51
45
  list Podio.connection.get { |req|
@@ -54,7 +48,6 @@ module Podio
54
48
  end
55
49
 
56
50
  def find_all_for_connection_type(connection_type, options={})
57
- options.assert_valid_keys(:key, :value, :limit, :offset, :type, :order, :name, :email)
58
51
  options[:type] ||= 'full'
59
52
 
60
53
  list Podio.connection.get { |req|
@@ -70,6 +63,10 @@ module Podio
70
63
  member Podio.connection.get("/contact/user/#{user_id}").body
71
64
  end
72
65
 
66
+ def vcard(profile_id)
67
+ Podio.connection.get("/contact/#{profile_id}/vcard").body
68
+ end
69
+
73
70
  def totals_by_org
74
71
  Podio.connection.get("/contact/totals/").body
75
72
  end
@@ -79,7 +76,6 @@ module Podio
79
76
  end
80
77
 
81
78
  def totals_by_space(space_id, options = {})
82
- options.assert_valid_keys(:exclude_self)
83
79
  options[:exclude_self] = (options[:exclude_self] == false ? "0" : "1" )
84
80
 
85
81
  Podio.connection.get { |req|
@@ -24,9 +24,16 @@ module Podio
24
24
  req.url "/conversation/#{ref_type}/#{ref_id}/"
25
25
  req.body = attributes
26
26
  end
27
-
28
27
  response.body
29
28
  end
29
+
30
+ def create_reply(conversation_id, text)
31
+ response = Podio.connection.post do |req|
32
+ req.url "/conversation/#{conversation_id}/reply"
33
+ req.body = { :text => text }
34
+ end
35
+ response.body['message_id']
36
+ end
30
37
 
31
38
  end
32
39
  end
@@ -15,20 +15,66 @@ module Podio
15
15
  end
16
16
 
17
17
  # Then, when the file has been moved, it must be marked as available
18
- def set_available(file_id)
19
- Podio.connection.post "/file/#{file_id}/available"
18
+ def set_available(id)
19
+ Podio.connection.post "/file/#{id}/available"
20
20
  end
21
21
 
22
22
  # Attach a file to an existing reference
23
- def attach(file_id, ref_type, ref_id)
23
+ def attach(id, ref_type, ref_id)
24
24
  Podio.connection.post do |req|
25
- req.url "/file/#{file_id}/attach"
25
+ req.url "/file/#{id}/attach"
26
26
  req.body = { :ref_type => ref_type, :ref_id => ref_id }
27
27
  end
28
28
  end
29
29
 
30
- def copy(file_id)
31
- Podio.connection.post("/file/#{file_id}/copy").body['file_id']
30
+ def copy(id)
31
+ Podio.connection.post("/file/#{id}/copy").body['id']
32
+ end
33
+
34
+ def delete(id)
35
+ Podio.connection.delete("/file/#{id}")
36
+ end
37
+
38
+ def find(id)
39
+ member Podio.connection.get("/file/#{id}").body
40
+ end
41
+
42
+ def find_for_app(app_id, options={})
43
+ collection Podio.connection.get { |req|
44
+ req.url("/file/app/#{app_id}/", options)
45
+ }.body
46
+ end
47
+
48
+ def find_for_space(space_id, options={})
49
+ collection Podio.connection.get { |req|
50
+ req.url("/file/space/#{space_id}/", options)
51
+ }.body
52
+ end
53
+
54
+ def find_latest_for_app(app_id, options={})
55
+ collection Podio.connection.get { |req|
56
+ req.url("/file/app/#{app_id}/latest/", options)
57
+ }.body
58
+ end
59
+
60
+ def find_latest_for_space(space_id, options={})
61
+ collection Podio.connection.get { |req|
62
+ req.url("/file/space/#{space_id}/latest/", options)
63
+ }.body
64
+ end
65
+
66
+ def replace(old_file_id, new_file_id)
67
+ Podio.connection.post { |req|
68
+ req.url "/file/#{new_file_id}/replace"
69
+ req.body = { :old_file_id => old_file_id }
70
+ }.body
71
+ end
72
+
73
+ def update(id, description)
74
+ Podio.connection.put { |req|
75
+ req.url "/file/#{file_id}"
76
+ req.body = { :description => description }
77
+ }.body
32
78
  end
33
79
 
34
80
  end
@@ -0,0 +1,38 @@
1
+ module Podio
2
+ module Hook
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def create(hookable_type, hookable_id, attributes)
7
+ response = Podio.connection.post do |req|
8
+ req.url "/hook/#{hookable_type}/#{hookable_id}/"
9
+ req.body = {:url => attributes[:url], :type => attributes[:type]}
10
+ end
11
+
12
+ response.body['hook_id']
13
+ end
14
+
15
+ def verify(hook_id)
16
+ Podio.connection.post do |req|
17
+ req.url "/hook/#{hook_id}/verify/request"
18
+ end
19
+ end
20
+
21
+ def validate(hook_id, code)
22
+ Podio.connection.post do |req|
23
+ req.url "/hook/#{hook_id}/verify/validate"
24
+ req.body = {:code => code}
25
+ end
26
+ end
27
+
28
+ def delete(hook_id)
29
+ Podio.connection.delete do |req|
30
+ req.url "/hook/#{hook_id}"
31
+ end
32
+ end
33
+
34
+ def find_all_for(hookable_type, hookable_id)
35
+ list Podio.connection.get("/hook/#{hookable_type}/#{hookable_id}/").body
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ module Podio
2
+ module Importer
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def process_file(file_id, app_id, mappings)
7
+ response = Podio.connection.post do |req|
8
+ req.url "/importer/#{file_id}/process"
9
+ req.body = {
10
+ :app_id => app_id,
11
+ :mappings => mappings
12
+ }
13
+ end
14
+
15
+ response.body
16
+ end
17
+
18
+ def get_columns(file_id)
19
+ list Podio.connection.get("/importer/#{file_id}/column/").body
20
+ end
21
+
22
+ end
23
+ end
@@ -39,5 +39,9 @@ module Podio
39
39
  def delete(app_id)
40
40
  Podio.connection.delete("/integration/#{app_id}").status
41
41
  end
42
+
43
+ def refresh(app_id)
44
+ Podio.connection.post("/integration/#{app_id}/refresh").status
45
+ end
42
46
  end
43
47
  end
@@ -16,14 +16,29 @@ module Podio
16
16
  end
17
17
 
18
18
  def find_all(app_id, options={})
19
- options.assert_valid_keys(:key, :limit, :offset, :sort_by, :sort_desc)
20
-
21
19
  collection Podio.connection.get { |req|
22
20
  req.url("/item/app/#{app_id}/", options)
23
21
  }.body
24
22
  end
25
-
26
23
 
24
+ def find_next(current_item_id, time = nil)
25
+ find_next_or_previous(:next, current_item_id, time)
26
+ end
27
+
28
+ def find_previous(current_item_id, time = nil)
29
+ find_next_or_previous(:previous, current_item_id, time)
30
+ end
31
+
32
+ def revisions(item_id)
33
+ collection Podio.connection.get("/item/#{item_id}/revision/").body
34
+ end
35
+
36
+ def revision_difference(item_id, revision_from_id, revision_to_id)
37
+ list Podio.connection.get{ |req|
38
+ req.url("/item/#{item_id}/revision/#{revision_from_id}/#{revision_to_id}")
39
+ }.body
40
+ end
41
+
27
42
  def create(app_id, attributes)
28
43
  response = Podio.connection.post do |req|
29
44
  req.url "/item/app/#{app_id}/"
@@ -31,6 +46,23 @@ module Podio
31
46
  end
32
47
 
33
48
  response.body['item_id']
34
- end
49
+ end
50
+
51
+ def delete(id)
52
+ Podio.connection.delete("/item/#{id}").body
53
+ end
54
+
55
+ protected
56
+
57
+ def time_options(time)
58
+ time.present? ? { 'time' => (time.is_a?(String) ? time : time.to_s(:db)) } : {}
59
+ end
60
+
61
+ def find_next_or_previous(operation, current_item_id, time)
62
+ member Podio.connection.get { |req|
63
+ req.url("/item/#{current_item_id}/#{operation}", time_options(time))
64
+ }.body
65
+ end
66
+
35
67
  end
36
68
  end
@@ -0,0 +1,39 @@
1
+ module Podio
2
+ module Notification
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def find(id)
7
+ member Podio.connection.get("/notification/#{id}").body
8
+ end
9
+
10
+ def mark_as_viewed(id)
11
+ Podio.connection.post("/notification/#{id}/viewed").status
12
+ end
13
+
14
+ def mark_all_as_viewed(id)
15
+ Podio.connection.post("/notification/viewed").status
16
+ end
17
+
18
+ def star(id)
19
+ Podio.connection.post("/notification/#{id}/star").status
20
+ end
21
+
22
+ def unstar(id)
23
+ Podio.connection.delete("/notification/#{id}/star").status
24
+ end
25
+
26
+ end
27
+
28
+ module NotificationGroup
29
+ include Podio::ResponseWrapper
30
+ extend self
31
+
32
+ def find_all(options={})
33
+ list Podio.connection.get { |req|
34
+ req.url('/notification/', options)
35
+ }.body
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,89 @@
1
+ module Podio
2
+ module OAuth
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def authorize(attributes)
7
+ response = Podio.connection.post do |req|
8
+ req.url "/oauth/authorize"
9
+ req.body = attributes
10
+ end
11
+
12
+ response.body
13
+ end
14
+
15
+ def get_info(attributes)
16
+ response = Podio.connection.post do |req|
17
+ req.url "/oauth/info"
18
+ req.body = attributes
19
+ end
20
+
21
+ response.body
22
+ end
23
+
24
+ def get_access_token(attributes)
25
+ response = Podio.connection.post do |req|
26
+ req.url "/oauth/token"
27
+ req.body = attributes
28
+ end
29
+
30
+ response.body
31
+ end
32
+
33
+ module OAuthClient
34
+ include Podio::ResponseWrapper
35
+ extend self
36
+
37
+ def create_admin(user_id, attributes)
38
+ response = Podio.connection.post do |req|
39
+ req.url "/oauth/client/user/#{user_id}/"
40
+ req.body = attributes
41
+ end
42
+
43
+ response.status
44
+ end
45
+
46
+ def update(id, attributes)
47
+ response = Podio.connection.put do |req|
48
+ req.url "/oauth/client/#{id}"
49
+ req.body = attributes
50
+ end
51
+
52
+ response.status
53
+ end
54
+
55
+ def update_admin(id, attributes)
56
+ response = Podio.connection.put do |req|
57
+ req.url "/oauth/client/#{id}/admin"
58
+ req.body = attributes
59
+ end
60
+
61
+ response.status
62
+ end
63
+
64
+ def delete(id)``
65
+ response = Podio.connection.delete("/oauth/client/#{id}")
66
+
67
+ response.status
68
+ end
69
+
70
+ def delete_grant(id)
71
+ response = Podio.connection.delete("/oauth/grant/client/#{id}")
72
+
73
+ response.status
74
+ end
75
+
76
+ def find_granted_clients()
77
+ list Podio.connection.get("oauth/grant/client/").body
78
+ end
79
+
80
+ def find_all_for_user(user_id)
81
+ list Podio.connection.get("oauth/client/user/#{user_id}/").body
82
+ end
83
+
84
+ def find(client_id)
85
+ member Podio.connection.get("oauth/client/#{client_id}").body
86
+ end
87
+ end
88
+ end
89
+ end
@@ -48,8 +48,6 @@ module Podio
48
48
  end
49
49
 
50
50
  def get_login_report(id, options = {})
51
- options.assert_valid_keys(:limit, :offset)
52
-
53
51
  Podio.connection.get { |req|
54
52
  req.url("/org/#{id}/report/login/", options)
55
53
  }.body
@@ -4,8 +4,6 @@ module Podio
4
4
  extend self
5
5
 
6
6
  def find_all_for_org(org_id, options = {})
7
- options.assert_valid_keys(:sort_by, :sort_desc, :limit, :offset)
8
-
9
7
  list Podio.connection.get { |req|
10
8
  req.url("/org/#{org_id}/member/", options)
11
9
  }.body
@@ -0,0 +1,36 @@
1
+ module Podio
2
+ module Rating
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def create(ref_type, ref_id, rating_type, value)
7
+ response = Podio.connection.post do |req|
8
+ req.url "/rating/#{ref_type}/#{ref_id}/#{rating_type}"
9
+ req.body = { :value => value }
10
+ end
11
+
12
+ response.body['rating_id']
13
+ end
14
+
15
+ def find_all(ref_type, ref_id)
16
+ collection Podio.connection.get("/rating/#{ref_type}/#{ref_id}").body
17
+ end
18
+
19
+ def find(ref_type, ref_id, rating_type, user_id)
20
+ Podio.connection.get("/rating/#{ref_type}/#{ref_id}/#{rating_type}/#{user_id}").body['value']
21
+ end
22
+
23
+ def find_own(ref_type, ref_id, rating_type)
24
+ Podio.connection.get("/rating/#{ref_type}/#{ref_id}/#{rating_type}/self").body['value']
25
+ end
26
+
27
+ def find_all_by_type(ref_type, ref_id, rating_type)
28
+ collection Podio.connection.get("/rating/#{ref_type}/#{ref_id}/#{rating_type}").body
29
+ end
30
+
31
+ def delete(ref_type, ref_id, rating_type)
32
+ Podio.connection.delete("/rating/#{ref_type}/#{ref_id}/#{rating_type}").body
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,26 @@
1
+ module Podio
2
+ module Subscription
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def find(id)
7
+ member Podio.connection.get("/subscription/#{id}").body
8
+ end
9
+
10
+ def find_by_reference(ref_type, ref_id)
11
+ member Podio.connection.get("/subscription/#{ref_type}/#{ref_id}").body
12
+ end
13
+
14
+ def create(ref_type, ref_id)
15
+ Podio.connection.post("/subscription/#{ref_type}/#{ref_id}").body['subscription_id']
16
+ end
17
+
18
+ def delete(id)
19
+ Podio.connection.delete("/subscription/#{id}}")
20
+ end
21
+
22
+ def delete_by_reference(ref_type, ref_id)
23
+ Podio.connection.delete("/subscription/#{ref_type}/#{ref_id}")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Podio
2
+ module Tag
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def create(tagable_type, tagable_id, attributes)
7
+ response = Podio.connection.post do |req|
8
+ req.url "/tag/#{tagable_type}/#{tagable_id}/"
9
+ req.body = attributes
10
+ end
11
+
12
+ response.body
13
+ end
14
+
15
+ def find_by_app(app_id, limit, text)
16
+ list Podio.connection.get("/tag/app/#{app_id}/?limit=#{limit}&text=#{text}").body
17
+ end
18
+
19
+ def find_top_by_app(app_id, limit, text)
20
+ Podio.connection.get("/tag/app/#{app_id}/top/?limit=#{limit}&text=#{text}").body
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -41,6 +41,10 @@ module Podio
41
41
  Podio.connection.post("/task/#{id}/assign", {:responsible => user_id}).status
42
42
  end
43
43
 
44
+ def update_reference(id, ref_type, ref_id)
45
+ Podio.connection.put("/task/#{id}/ref", {:ref_type => ref_type, :ref_id => ref_id}).status
46
+ end
47
+
44
48
  def update_labels(id, label_ids)
45
49
  Podio.connection.put("/task/#{id}/label/", label_ids).status
46
50
  end
@@ -95,8 +99,8 @@ module Podio
95
99
  Podio.connection.delete("/task/label/#{label_id}").status
96
100
  end
97
101
 
98
- def update(label_id, text, color)
99
- Podio.connection.put("/task/label/#{label_id}", {:text => text, :color => color}).status
102
+ def update(label_id, attributes)
103
+ Podio.connection.put("/task/label/#{label_id}", attributes).status
100
104
  end
101
105
 
102
106
  end
@@ -19,5 +19,13 @@ module Podio
19
19
  def find_all_admins_for_org(org_id)
20
20
  list Podio.connection.get("/org/#{org_id}/admin/").body
21
21
  end
22
+
23
+ def get_property(name, value)
24
+ Podio.connection.get("/user/property/#{name}").body['value']
25
+ end
26
+
27
+ def set_property(name, value)
28
+ Podio.connection.put("/user/property/#{name}", {:value => value}).status
29
+ end
22
30
  end
23
31
  end
data/lib/podio/client.rb CHANGED
@@ -58,6 +58,7 @@ module Podio
58
58
  end
59
59
 
60
60
  @oauth_token.access_token = response.body['access_token']
61
+ @oauth_token.refreshed = true
61
62
  configure_oauth
62
63
  end
63
64
 
data/lib/podio/error.rb CHANGED
@@ -5,6 +5,7 @@ module Podio
5
5
  class BadRequestError < StandardError; end
6
6
  class ServerError < StandardError; end
7
7
  class NotFoundError < StandardError; end
8
+ class ConflictError < StandardError; end
8
9
  class GoneError < StandardError; end
9
10
  class Unavailable < StandardError; end
10
11
  end
@@ -3,7 +3,7 @@ module Podio
3
3
  class DateConversion < Faraday::Response::Middleware
4
4
  def self.register_on_complete(env)
5
5
  env[:response].on_complete do |finished_env|
6
- convert_dates(finished_env[:body])
6
+ convert_dates(finished_env[:body]) if finished_env[:body].is_a?(Hash)
7
7
  end
8
8
  end
9
9
 
@@ -6,6 +6,8 @@ module Podio
6
6
  def self.register_on_complete(env)
7
7
  env[:response].on_complete do |finished_env|
8
8
  case finished_env[:status]
9
+ when 200, 204
10
+ # pass
9
11
  when 400
10
12
  raise Error::BadRequestError, finished_env[:body]
11
13
  when 401
@@ -18,12 +20,17 @@ module Podio
18
20
  raise Error::AuthorizationError, finished_env[:body]
19
21
  when 404
20
22
  raise Error::NotFoundError, "#{finished_env[:method].to_s.upcase} #{finished_env[:url]}"
23
+ when 409
24
+ raise Error::ConflictError, finished_env[:body]
21
25
  when 410
22
26
  raise Error::GoneError, "#{finished_env[:method].to_s.upcase} #{finished_env[:url]}"
23
27
  when 500
24
28
  raise Error::ServerError, finished_env[:body].inspect
25
29
  when 502, 503
26
30
  raise Error::Unavailable, finished_env[:body].inspect
31
+ else
32
+ # anything else is something unexpected, so raise it
33
+ raise Error::ServerError, finished_env[:body].inspect
27
34
  end
28
35
  end
29
36
  end
@@ -8,7 +8,7 @@ module Podio
8
8
 
9
9
  def self.register_on_complete(env)
10
10
  env[:response].on_complete do |finished_env|
11
- if finished_env[:body].is_a?(String) && finished_env[:status] < 500
11
+ if finished_env[:body].is_a?(String) && is_json?(finished_env) && finished_env[:status] < 500
12
12
  finished_env[:body] = parse(finished_env[:body])
13
13
  end
14
14
  end
@@ -19,6 +19,10 @@ module Podio
19
19
  @parser = nil
20
20
  end
21
21
 
22
+ def self.is_json?(finished_env)
23
+ finished_env[:response_headers]['content-type'] =~ /application\/json/
24
+ end
25
+
22
26
  def self.parse(body)
23
27
  return nil if body !~ /\S/ # json gem doesn't like decoding blank strings
24
28
  MultiJson.decode(body)
data/lib/podio/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Podio
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: podio
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Munz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-05 00:00:00 +02:00
13
+ date: 2011-05-04 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -83,14 +83,21 @@ files:
83
83
  - lib/podio/areas/conversation.rb
84
84
  - lib/podio/areas/file.rb
85
85
  - lib/podio/areas/form.rb
86
+ - lib/podio/areas/hook.rb
87
+ - lib/podio/areas/importer.rb
86
88
  - lib/podio/areas/integration.rb
87
89
  - lib/podio/areas/item.rb
90
+ - lib/podio/areas/notification.rb
91
+ - lib/podio/areas/oauth.rb
88
92
  - lib/podio/areas/organization.rb
89
93
  - lib/podio/areas/organization_member.rb
90
94
  - lib/podio/areas/organization_profile.rb
95
+ - lib/podio/areas/rating.rb
91
96
  - lib/podio/areas/search.rb
92
97
  - lib/podio/areas/space.rb
93
98
  - lib/podio/areas/status.rb
99
+ - lib/podio/areas/subscription.rb
100
+ - lib/podio/areas/tag.rb
94
101
  - lib/podio/areas/task.rb
95
102
  - lib/podio/areas/user.rb
96
103
  - lib/podio/areas/user_status.rb