podio 0.2.0 → 0.2.1

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.
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rake'
1
2
  require 'rake/testtask'
2
3
  require 'bundler'
3
4
 
@@ -5,6 +6,9 @@ Bundler::GemHelper.install_tasks
5
6
 
6
7
  desc 'Run tests'
7
8
  Rake::TestTask.new(:test) do |t|
9
+ #ENV['ENABLE_STUBS'] = 'true'
10
+ t.ruby_opts = ["-rubygems"] if defined? Gem
11
+ t.libs << "lib" << "test"
8
12
  t.pattern = 'test/**/*_test.rb'
9
13
  t.verbose = true
10
14
  end
data/lib/podio.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require 'faraday'
2
2
  require 'active_support/core_ext'
3
3
 
4
+ require 'podio/middleware/json_request'
4
5
  require 'podio/middleware/date_conversion'
5
6
  require 'podio/middleware/logger'
6
7
  require 'podio/middleware/oauth2'
7
8
  require 'podio/middleware/podio_api'
8
- require 'podio/middleware/yajl_response'
9
+ require 'podio/middleware/json_response'
9
10
  require 'podio/middleware/error_response'
10
11
  require 'podio/middleware/response_recorder'
11
12
 
@@ -48,6 +49,7 @@ module Podio
48
49
 
49
50
  autoload :Application, 'podio/areas/application'
50
51
  autoload :Category, 'podio/areas/app_store'
52
+ autoload :Connection, 'podio/areas/connection'
51
53
  autoload :Contact, 'podio/areas/contact'
52
54
  autoload :File, 'podio/areas/file'
53
55
  autoload :Form, 'podio/areas/form'
@@ -0,0 +1,31 @@
1
+ module Podio
2
+ module Connection
3
+ include Podio::ResponseWrapper
4
+ extend self
5
+
6
+ def create(attributes)
7
+ response = Podio.connection.post do |req|
8
+ req.url '/connection/'
9
+ req.body = attributes
10
+ end
11
+
12
+ response.body['connection_id']
13
+ end
14
+
15
+ def reload(id)
16
+ Podio.connection.post("/connection/#{id}/load").body
17
+ end
18
+
19
+ def find(id)
20
+ member Podio.connection.get("/connection/#{id}").body
21
+ end
22
+
23
+ def delete(id)
24
+ Podio.connection.delete("/connection/#{id}").status
25
+ end
26
+
27
+ def all(options={})
28
+ list Podio.connection.get('/connection/').body
29
+ end
30
+ end
31
+ end
@@ -11,8 +11,8 @@ module Podio
11
11
  }.body
12
12
  end
13
13
 
14
- def find(user_id)
15
- member Podio.connection.get("/contact/#{user_id}").body
14
+ def find(profile_id)
15
+ member Podio.connection.get("/contact/#{profile_id}/v2").body
16
16
  end
17
17
 
18
18
  def find_all_for_org(org_id, options={})
@@ -23,7 +23,24 @@ module Podio
23
23
  req.url("/contact/org/#{org_id}", options)
24
24
  }.body
25
25
  end
26
-
26
+
27
+ def find_all_for_space(space_id, options={})
28
+ options.assert_valid_keys(:key, :value, :limit, :offset, :type, :order)
29
+ options[:type] ||= 'full'
30
+
31
+ list Podio.connection.get { |req|
32
+ req.url("/contact/space/#{space_id}", options)
33
+ }.body
34
+ end
35
+
36
+ def find_all_for_connection(connection_id)
37
+ list Podio.connection.get("/contact/connection/#{connection_id}").body
38
+ end
39
+
40
+ def find_all_for_connection_type(connection_type)
41
+ list Podio.connection.get("/contact/connection/#{connection_type}").body
42
+ end
43
+
27
44
  def find_for_org(org_id)
28
45
  member Podio.connection.get("/org/#{org_id}/profile").body
29
46
  end
@@ -31,6 +48,10 @@ module Podio
31
48
  def totals_by_org
32
49
  Podio.connection.get("/contact/totals/").body
33
50
  end
51
+
52
+ def totals_by_org_and_space
53
+ Podio.connection.get("/contact/totals/v2/").body
54
+ end
34
55
 
35
56
  end
36
57
  end
data/lib/podio/client.rb CHANGED
@@ -73,13 +73,13 @@ module Podio
73
73
 
74
74
  def configure_connection
75
75
  Faraday::Connection.new(:url => api_url, :headers => configured_headers, :request => {:client => self}) do |builder|
76
- builder.use Faraday::Request::Yajl
76
+ builder.use Middleware::JsonRequest
77
77
  builder.use Middleware::PodioApi
78
78
  builder.use Middleware::OAuth2
79
79
  builder.use Middleware::Logger
80
80
  builder.adapter(*default_adapter)
81
81
  builder.use Middleware::ResponseRecorder if @record_mode
82
- builder.use Middleware::YajlResponse
82
+ builder.use Middleware::JsonResponse
83
83
  builder.use Middleware::ErrorResponse
84
84
  builder.use Middleware::DateConversion
85
85
  end
data/lib/podio/error.rb CHANGED
@@ -6,5 +6,6 @@ module Podio
6
6
  class ServerError < StandardError; end
7
7
  class NotFoundError < StandardError; end
8
8
  class GoneError < StandardError; end
9
+ class Unavailable < StandardError; end
9
10
  end
10
11
  end
@@ -22,6 +22,8 @@ module Podio
22
22
  raise Error::GoneError, "#{finished_env[:method].to_s.upcase} #{finished_env[:url]}"
23
23
  when 500
24
24
  raise Error::ServerError, finished_env[:body].inspect
25
+ when 502, 503
26
+ raise Error::Unavailable, finished_env[:body].inspect
25
27
  end
26
28
  end
27
29
  end
@@ -0,0 +1,20 @@
1
+ module Podio
2
+ module Middleware
3
+ class JsonRequest < Faraday::Middleware
4
+ begin
5
+ require 'multi_json'
6
+
7
+ rescue LoadError, NameError => e
8
+ self.load_error = e
9
+ end
10
+
11
+ def call(env)
12
+ env[:request_headers]['Content-Type'] = 'application/json'
13
+ if env[:body] && !env[:body].respond_to?(:to_str)
14
+ env[:body] = MultiJson.encode(env[:body])
15
+ end
16
+ @app.call env
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,15 +1,17 @@
1
- # Custom Yajl until I find a way to only parse the body once in
1
+ # Custom Json response until I find a way to only parse the body once in
2
2
  # the OAuth2 retry case
3
3
  #
4
4
  module Podio
5
5
  module Middleware
6
- class YajlResponse < Faraday::Response::Middleware
6
+ class JsonResponse < Faraday::Response::Middleware
7
7
  begin
8
- require 'yajl'
8
+ require 'multi_json'
9
9
 
10
10
  def self.register_on_complete(env)
11
11
  env[:response].on_complete do |finished_env|
12
- finished_env[:body] = parse(finished_env[:body]) if finished_env[:body].is_a?(String)
12
+ if finished_env[:body].is_a?(String) && finished_env[:status] < 500
13
+ finished_env[:body] = parse(finished_env[:body])
14
+ end
13
15
  end
14
16
  end
15
17
  rescue LoadError, NameError => e
@@ -22,7 +24,7 @@ module Podio
22
24
  end
23
25
 
24
26
  def self.parse(body)
25
- Yajl::Parser.parse(body)
27
+ MultiJson.decode(body)
26
28
  rescue Object => err
27
29
  raise Faraday::Error::ParsingError.new(err)
28
30
  end
data/lib/podio/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Podio
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/podio.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_runtime_dependency 'faraday', '~> 0.5.1'
19
19
  s.add_runtime_dependency 'activesupport', '~> 3.0'
20
- s.add_runtime_dependency 'yajl-ruby', '~> 0.7'
20
+ s.add_runtime_dependency 'multi_json', '~> 0.0.5'
21
21
 
22
22
  s.description = <<desc
23
23
  The humble beginnings of the Ruby wrapper for the Podio API.
@@ -1,6 +1,6 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
- class AppStoreTest < ActiveSupport::TestCase
3
+ class AppStoreTest < Test::Unit::TestCase
4
4
  test 'should find single category' do
5
5
  category = Podio::Category.find(1)
6
6
 
data/test/client_test.rb CHANGED
@@ -1,6 +1,6 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
- class ClientTest < ActiveSupport::TestCase
3
+ class ClientTest < Test::Unit::TestCase
4
4
  def setup
5
5
  Podio.configure do |config|
6
6
  config.api_url = 'https://api.podio.com'
data/test/contact_test.rb CHANGED
@@ -1,6 +1,6 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
- class ContactTest < ActiveSupport::TestCase
3
+ class ContactTest < Test::Unit::TestCase
4
4
  test 'should find single contact' do
5
5
  contact = Podio::Contact.find(1)
6
6
 
@@ -16,11 +16,11 @@ class ContactTest < ActiveSupport::TestCase
16
16
  end
17
17
 
18
18
  test 'should find all for org filtered by key' do
19
- contacts = Podio::Contact.find_all_for_org(1, :key => 'organization', :value => 'kolios')
19
+ contacts = Podio::Contact.find_all_for_org(1, :key => 'organization', :value => 'Hoist')
20
20
 
21
21
  assert contacts.size > 0
22
22
  contacts.each do |contact|
23
- assert_equal 'kolios', contact['organization']
23
+ assert_equal 'Hoist', contact['organization']
24
24
  end
25
25
  end
26
26
  end
data/test/item_test.rb CHANGED
@@ -1,6 +1,6 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
- class ItemTest < ActiveSupport::TestCase
3
+ class ItemTest < Test::Unit::TestCase
4
4
  test 'should find single item' do
5
5
  item = Podio::Item.find(1)
6
6
 
@@ -17,14 +17,14 @@ class ItemTest < ActiveSupport::TestCase
17
17
  end
18
18
 
19
19
  test 'should find items by external id' do
20
- items = Podio::Item.find_all_by_external_id(1, 'Foo generator')
20
+ items = Podio::Item.find_all_by_external_id(1, 'Bar generator')
21
21
 
22
22
  assert items['count'] > 0
23
23
  assert items['total_count'] > 0
24
24
 
25
25
  assert items['all'].is_a?(Array)
26
26
  items['all'].each do |item|
27
- assert_equal 'Foo generator', item['external_id']
27
+ assert_equal 'Bar generator', item['external_id']
28
28
  end
29
29
  end
30
30
 
@@ -1,6 +1,6 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
- class OrganizationTest < ActiveSupport::TestCase
3
+ class OrganizationTest < Test::Unit::TestCase
4
4
  test 'should find single organization' do
5
5
  org = Podio::Organization.find(1)
6
6
 
data/test/space_test.rb CHANGED
@@ -1,14 +1,14 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
- class SpaceTest < ActiveSupport::TestCase
4
- test 'should find single space' do
3
+ class SpaceTest < Test::Unit::TestCase
4
+ def test_should_find_single_space
5
5
  space = Podio::Space.find(1)
6
6
 
7
7
  assert_equal 1, space['space_id']
8
8
  assert_equal 'API', space['name']
9
9
  end
10
10
 
11
- test 'should find all for org' do
11
+ def test_should_find_all_for_org
12
12
  spaces = Podio::Space.find_all_for_org(1)
13
13
 
14
14
  assert spaces.is_a?(Array)
data/test/test_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'test/unit'
2
2
  require 'yajl'
3
- require 'active_support'
4
3
 
5
4
  require 'podio'
6
5
 
@@ -8,9 +7,28 @@ require 'podio'
8
7
  ENABLE_STUBS = ENV['ENABLE_STUBS'] == 'true'
9
8
  ENABLE_RECORD = ENV['ENABLE_RECORD'] == 'true'
10
9
 
11
- class ActiveSupport::TestCase
12
- setup :set_podio_client
13
- setup :stub_responses if ENABLE_STUBS
10
+ class Test::Unit::TestCase
11
+
12
+ def setup
13
+ set_podio_client
14
+ stub_responses if ENABLE_STUBS
15
+ end
16
+
17
+ # test "verify something" do
18
+ # ...
19
+ # end
20
+ def self.test(name, &block)
21
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
22
+ defined = instance_method(test_name) rescue false
23
+ raise "#{test_name} is already defined in #{self}" if defined
24
+ if block_given?
25
+ define_method(test_name, &block)
26
+ else
27
+ define_method(test_name) do
28
+ flunk "No implementation provided for #{name}"
29
+ end
30
+ end
31
+ end
14
32
 
15
33
  def set_podio_client(user_id = 1)
16
34
  Podio.client = Podio::Client.new(
data/test/widget_test.rb CHANGED
@@ -1,6 +1,6 @@
1
- require_relative 'test_helper'
1
+ require 'test_helper'
2
2
 
3
- class WidgetTest < ActiveSupport::TestCase
3
+ class WidgetTest < Test::Unit::TestCase
4
4
  test 'should find single widget' do
5
5
  widget = Podio::Widget.find(1)
6
6
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Munz
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-23 00:00:00 +01:00
17
+ date: 2011-01-28 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :runtime
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: yajl-ruby
50
+ name: multi_json
51
51
  prerelease: false
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -56,8 +56,9 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  segments:
58
58
  - 0
59
- - 7
60
- version: "0.7"
59
+ - 0
60
+ - 5
61
+ version: 0.0.5
61
62
  type: :runtime
62
63
  version_requirements: *id003
63
64
  description: |
@@ -79,6 +80,7 @@ files:
79
80
  - lib/podio.rb
80
81
  - lib/podio/areas/app_store.rb
81
82
  - lib/podio/areas/application.rb
83
+ - lib/podio/areas/connection.rb
82
84
  - lib/podio/areas/contact.rb
83
85
  - lib/podio/areas/file.rb
84
86
  - lib/podio/areas/form.rb
@@ -94,11 +96,12 @@ files:
94
96
  - lib/podio/error.rb
95
97
  - lib/podio/middleware/date_conversion.rb
96
98
  - lib/podio/middleware/error_response.rb
99
+ - lib/podio/middleware/json_request.rb
100
+ - lib/podio/middleware/json_response.rb
97
101
  - lib/podio/middleware/logger.rb
98
102
  - lib/podio/middleware/oauth2.rb
99
103
  - lib/podio/middleware/podio_api.rb
100
104
  - lib/podio/middleware/response_recorder.rb
101
- - lib/podio/middleware/yajl_response.rb
102
105
  - lib/podio/response_wrapper.rb
103
106
  - lib/podio/version.rb
104
107
  - podio.gemspec