podio 0.1.0 → 0.2.0

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.
@@ -0,0 +1,26 @@
1
+ require_relative 'test_helper'
2
+
3
+ class ContactTest < ActiveSupport::TestCase
4
+ test 'should find single contact' do
5
+ contact = Podio::Contact.find(1)
6
+
7
+ assert_equal 1, contact['user_id']
8
+ assert_equal 'King of the API, baby!', contact['about']
9
+ end
10
+
11
+ test 'should find all for org' do
12
+ contacts = Podio::Contact.find_all_for_org(1)
13
+
14
+ assert contacts.size > 0
15
+ assert_not_nil contacts.first['user_id']
16
+ end
17
+
18
+ test 'should find all for org filtered by key' do
19
+ contacts = Podio::Contact.find_all_for_org(1, :key => 'organization', :value => 'kolios')
20
+
21
+ assert contacts.size > 0
22
+ contacts.each do |contact|
23
+ assert_equal 'kolios', contact['organization']
24
+ end
25
+ end
26
+ end
data/test/item_test.rb ADDED
@@ -0,0 +1,37 @@
1
+ require_relative 'test_helper'
2
+
3
+ class ItemTest < ActiveSupport::TestCase
4
+ test 'should find single item' do
5
+ item = Podio::Item.find(1)
6
+
7
+ assert_equal 1, item['item_id']
8
+
9
+ assert_equal 1, item['app']['app_id']
10
+ assert_equal 'Bugs', item['app']['name']
11
+ end
12
+
13
+ test 'should not find nonexistant item' do
14
+ assert_raises Podio::Error::NotFoundError do
15
+ Podio::Item.find(42)
16
+ end
17
+ end
18
+
19
+ test 'should find items by external id' do
20
+ items = Podio::Item.find_all_by_external_id(1, 'Foo generator')
21
+
22
+ assert items['count'] > 0
23
+ assert items['total_count'] > 0
24
+
25
+ assert items['all'].is_a?(Array)
26
+ items['all'].each do |item|
27
+ assert_equal 'Foo generator', item['external_id']
28
+ end
29
+ end
30
+
31
+ test 'should not find anything for nonexistant external ids' do
32
+ items = Podio::Item.find_all_by_external_id(1, 'Random nonexistant')
33
+
34
+ assert_equal [], items['all']
35
+ assert_equal 0, items['count']
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'test_helper'
2
+
3
+ class OrganizationTest < ActiveSupport::TestCase
4
+ test 'should find single organization' do
5
+ org = Podio::Organization.find(1)
6
+
7
+ assert_equal 1, org['org_id']
8
+ assert_equal 'Hoist', org['name']
9
+ end
10
+
11
+ test 'should delete org' do
12
+ response = Podio::Organization.delete(1)
13
+ assert_equal 204, response
14
+ end
15
+
16
+ test 'should update org' do
17
+ response = Podio::Organization.update(1, :name => 'New name')
18
+ assert_equal 204, response
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'test_helper'
2
+
3
+ class SpaceTest < ActiveSupport::TestCase
4
+ test 'should find single space' do
5
+ space = Podio::Space.find(1)
6
+
7
+ assert_equal 1, space['space_id']
8
+ assert_equal 'API', space['name']
9
+ end
10
+
11
+ test 'should find all for org' do
12
+ spaces = Podio::Space.find_all_for_org(1)
13
+
14
+ assert spaces.is_a?(Array)
15
+ assert_not_nil spaces.first['name']
16
+ end
17
+ end
data/test/test_helper.rb CHANGED
@@ -1,61 +1,59 @@
1
1
  require 'test/unit'
2
2
  require 'yajl'
3
- require 'fakeweb'
3
+ require 'active_support'
4
4
 
5
5
  require 'podio'
6
6
 
7
7
 
8
- FakeWeb.allow_net_connect = false
8
+ ENABLE_STUBS = ENV['ENABLE_STUBS'] == 'true'
9
+ ENABLE_RECORD = ENV['ENABLE_RECORD'] == 'true'
9
10
 
10
- def podio_test_client
11
- token = Podio::OAuthToken.new('access_token' => 'access', 'refresh_token' => 'refresh', 'expires_in' => 3600)
12
- Podio::Client.new(:api_url => 'https://api.podio.com', :api_key => 'client_id', :api_secret => 'client_secret', :oauth_token => token)
13
- end
11
+ class ActiveSupport::TestCase
12
+ setup :set_podio_client
13
+ setup :stub_responses if ENABLE_STUBS
14
14
 
15
- def fixture_file(filename)
16
- return '' if filename == ''
17
- file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
18
- File.read(file_path)
19
- end
15
+ def set_podio_client(user_id = 1)
16
+ Podio.client = Podio::Client.new(
17
+ :api_url => 'http://127.0.0.1:8080',
18
+ :api_key => 'dev@hoisthq.com',
19
+ :api_secret => 'CmACRWF1WBOTDfOa20A',
20
+ :enable_stubs => ENABLE_STUBS && !ENABLE_RECORD,
21
+ :record_mode => ENABLE_RECORD,
22
+ :test_mode => true,
23
+ :oauth_token => new_token_for_user(user_id)
24
+ )
25
+ end
20
26
 
21
- def stub_get(url, body, options = {})
22
- opts = {
23
- :body => body.is_a?(String) ? body : Yajl::Encoder.encode(body),
24
- :content_type => 'application/json; charset=utf-8'
25
- }.merge(options)
26
- FakeWeb.register_uri(:get, "https://api.podio.com#{url}", opts)
27
- end
27
+ def login_as_user(user_id)
28
+ set_podio_client(user_id)
29
+ end
28
30
 
29
- def stub_post(url, body, options = {})
30
- opts = {
31
- :body => body.is_a?(String) ? body : Yajl::Encoder.encode(body),
32
- :content_type => 'application/json; charset=utf-8'
33
- }.merge(options)
34
- FakeWeb.register_uri(:post, "https://api.podio.com#{url}", opts)
35
- end
31
+ def stub_responses
32
+ folder_name = self.class.name.underscore.gsub('_test', '')
33
+ current_folder = File.join(File.dirname(__FILE__), 'fixtures', folder_name)
36
34
 
35
+ Dir.foreach(current_folder) do |filename|
36
+ next unless filename.include?('.rack')
37
37
 
38
- ##
39
- # test/spec/mini 5
40
- # http://gist.github.com/307649
41
- # chris@ozmm.org
42
- #
43
- def context(*args, &block)
44
- return super unless (name = args.first) && block
45
- require 'test/unit'
46
- klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
47
- def self.test(name, &block)
48
- define_method("test_#{name.to_s.gsub(/\W/,'_')}", &block) if block
49
- end
50
- def self.xtest(*args) end
51
- def self.context(*args, &block) instance_eval(&block) end
52
- def self.setup(&block)
53
- define_method(:setup) { self.class.setups.each { |s| instance_eval(&s) } }
54
- setups << block
38
+ rack_response = eval(File.read(File.join(current_folder, filename)))
39
+
40
+ url = rack_response.shift
41
+ method = rack_response.shift
42
+
43
+ Podio.client.stubs.send(method, url) { rack_response }
55
44
  end
56
- def self.setups; @setups ||= [] end
57
- def self.teardown(&block) define_method(:teardown, &block) end
58
45
  end
59
- (class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
60
- klass.class_eval(&block)
46
+
47
+ def new_token_for_user(user_id)
48
+ tokens = {
49
+ 1 => '352e85cd67eff86179194515b91a75404c1169ad083ad435b200af834b9121665b2aaf894f599b7d9b1bee6b7551f3a11e2a02dc43def9a9b549b1f2a4fe9a42',
50
+ 2 => '58ac6854ac3e8d7e8797ed5b37ba8dfeca4224cabcd4ad4f04a5f328c83d9edb3be911e6fbccf742841369734ab26136c66380385e58ff2b5da03f7fe45852b1'
51
+ }
52
+
53
+ Podio::OAuthToken.new(
54
+ 'access_token' => tokens[user_id],
55
+ 'refresh_token' => '82e7a11ae187f28a25261599aa6229cd89f8faee48cba18a75d70efae88ba665ced11d43143b7f5bebb31a4103662b851dd2db1879a3947b843259479fccfad3',
56
+ 'expires_in' => 3600
57
+ )
58
+ end
61
59
  end
@@ -0,0 +1,55 @@
1
+ require_relative 'test_helper'
2
+
3
+ class WidgetTest < ActiveSupport::TestCase
4
+ test 'should find single widget' do
5
+ widget = Podio::Widget.find(1)
6
+
7
+ assert_equal 1, widget['widget_id']
8
+ assert_equal 'State count', widget['title']
9
+ end
10
+
11
+ test 'should find all for reference' do
12
+ widgets = Podio::Widget.find_all_for_reference(:app, 1)
13
+
14
+ assert widgets.is_a?(Array)
15
+ assert widgets.size > 0
16
+ end
17
+
18
+ test 'should find nothing for reference' do
19
+ # no widgets exists for this space
20
+ widgets = Podio::Widget.find_all_for_reference(:space, 2)
21
+ assert_equal [], widgets
22
+ end
23
+
24
+ test 'should create widget' do
25
+ response = Podio::Widget.create(:app, 1, {
26
+ :type => :text,
27
+ :title => 'widget title',
28
+ :config => {:text => 'widget'}
29
+ })
30
+
31
+ assert response.is_a?(Integer)
32
+ end
33
+
34
+ test 'should not create widget with missing field' do
35
+ assert_raises Podio::Error::BadRequestError do
36
+ Podio::Widget.create(:app, 1, :title => 'widget title', :config => {:text => 'widget'})
37
+ end
38
+ end
39
+
40
+ test 'should update widget' do
41
+ status = Podio::Widget.update(3, :title => 'Updated title', :config => {:text => 'updated text'})
42
+ assert_equal 204, status
43
+ end
44
+
45
+ test 'should delete widget' do
46
+ status = Podio::Widget.delete(1)
47
+ assert_equal 204, status
48
+ end
49
+
50
+ test 'should update order of widgets' do
51
+ widgets_ids = Podio::Widget.find_all_for_reference(:space, 1).map { |w| w['widget_id'] }
52
+
53
+ Podio::Widget.update_order(:space, 1, widgets_ids.reverse)
54
+ end
55
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: podio
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
7
+ - 2
9
8
  - 0
10
- version: 0.1.0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Florian Munz
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-12-07 00:00:00 +01:00
17
+ date: 2011-01-23 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 9
30
28
  segments:
31
29
  - 0
32
30
  - 5
@@ -35,19 +33,17 @@ dependencies:
35
33
  type: :runtime
36
34
  version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
38
- name: hashie
36
+ name: activesupport
39
37
  prerelease: false
40
38
  requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 15
46
43
  segments:
44
+ - 3
47
45
  - 0
48
- - 4
49
- - 0
50
- version: 0.4.0
46
+ version: "3.0"
51
47
  type: :runtime
52
48
  version_requirements: *id002
53
49
  - !ruby/object:Gem::Dependency
@@ -58,29 +54,12 @@ dependencies:
58
54
  requirements:
59
55
  - - ~>
60
56
  - !ruby/object:Gem::Version
61
- hash: 3
62
57
  segments:
63
58
  - 0
64
59
  - 7
65
- - 0
66
- version: 0.7.0
60
+ version: "0.7"
67
61
  type: :runtime
68
62
  version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: fakeweb
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 9
78
- segments:
79
- - 1
80
- - 3
81
- version: "1.3"
82
- type: :development
83
- version_requirements: *id004
84
63
  description: |
85
64
  The humble beginnings of the Ruby wrapper for the Podio API.
86
65
 
@@ -98,17 +77,39 @@ files:
98
77
  - README.md
99
78
  - Rakefile
100
79
  - lib/podio.rb
80
+ - lib/podio/areas/app_store.rb
81
+ - lib/podio/areas/application.rb
82
+ - lib/podio/areas/contact.rb
83
+ - lib/podio/areas/file.rb
84
+ - lib/podio/areas/form.rb
85
+ - lib/podio/areas/item.rb
86
+ - lib/podio/areas/organization.rb
87
+ - lib/podio/areas/organization_member.rb
88
+ - lib/podio/areas/search.rb
89
+ - lib/podio/areas/space.rb
90
+ - lib/podio/areas/user.rb
91
+ - lib/podio/areas/user_status.rb
92
+ - lib/podio/areas/widget.rb
101
93
  - lib/podio/client.rb
94
+ - lib/podio/error.rb
95
+ - lib/podio/middleware/date_conversion.rb
102
96
  - lib/podio/middleware/error_response.rb
103
97
  - lib/podio/middleware/logger.rb
104
- - lib/podio/middleware/mashify.rb
105
98
  - lib/podio/middleware/oauth2.rb
106
99
  - lib/podio/middleware/podio_api.rb
100
+ - lib/podio/middleware/response_recorder.rb
107
101
  - lib/podio/middleware/yajl_response.rb
102
+ - lib/podio/response_wrapper.rb
108
103
  - lib/podio/version.rb
109
104
  - podio.gemspec
105
+ - test/app_store_test.rb
110
106
  - test/client_test.rb
107
+ - test/contact_test.rb
108
+ - test/item_test.rb
109
+ - test/organization_test.rb
110
+ - test/space_test.rb
111
111
  - test/test_helper.rb
112
+ - test/widget_test.rb
112
113
  has_rdoc: true
113
114
  homepage: https://github.com/podio/podio-rb
114
115
  licenses: []
@@ -123,7 +124,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
124
  requirements:
124
125
  - - ">="
125
126
  - !ruby/object:Gem::Version
126
- hash: 3
127
127
  segments:
128
128
  - 0
129
129
  version: "0"
@@ -132,7 +132,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - ">="
134
134
  - !ruby/object:Gem::Version
135
- hash: 3
136
135
  segments:
137
136
  - 0
138
137
  version: "0"
@@ -144,5 +143,11 @@ signing_key:
144
143
  specification_version: 3
145
144
  summary: Ruby wrapper for the Podio API
146
145
  test_files:
146
+ - test/app_store_test.rb
147
147
  - test/client_test.rb
148
+ - test/contact_test.rb
149
+ - test/item_test.rb
150
+ - test/organization_test.rb
151
+ - test/space_test.rb
148
152
  - test/test_helper.rb
153
+ - test/widget_test.rb
@@ -1,27 +0,0 @@
1
- module Podio
2
- module Middleware
3
- class Mashify < Faraday::Response::Middleware
4
- begin
5
- require 'hashie'
6
- rescue LoadError, NameError => error
7
- self.load_error = error
8
- end
9
-
10
- def self.register_on_complete(env)
11
- env[:response].on_complete do |response|
12
- response_body = response[:body]
13
- if response_body.is_a?(Hash)
14
- response[:body] = ::Hashie::Mash.new(response_body)
15
- elsif response_body.is_a?(Array) and response_body.first.is_a?(Hash)
16
- response[:body] = response_body.map{|item| ::Hashie::Mash.new(item)}
17
- end
18
- end
19
- end
20
-
21
- def initialize(app)
22
- super
23
- @parser = nil
24
- end
25
- end
26
- end
27
- end