whatser 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.document +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +34 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +310 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/lib/whatser/api/batch.rb +0 -0
  9. data/lib/whatser/api/facebook.rb +13 -0
  10. data/lib/whatser/api/foursquare.rb +5 -0
  11. data/lib/whatser/api/gowalla.rb +5 -0
  12. data/lib/whatser/api/response.rb +84 -0
  13. data/lib/whatser/api/service.rb +15 -0
  14. data/lib/whatser/api/twitter.rb +13 -0
  15. data/lib/whatser/client.rb +54 -0
  16. data/lib/whatser/configuration.rb +15 -0
  17. data/lib/whatser/errors.rb +4 -0
  18. data/lib/whatser/net/http.rb +26 -0
  19. data/lib/whatser/net/oauth.rb +41 -0
  20. data/lib/whatser/resources/activity_feed.rb +20 -0
  21. data/lib/whatser/resources/check_in.rb +25 -0
  22. data/lib/whatser/resources/city.rb +16 -0
  23. data/lib/whatser/resources/collection.rb +68 -0
  24. data/lib/whatser/resources/data_source.rb +24 -0
  25. data/lib/whatser/resources/detail.rb +40 -0
  26. data/lib/whatser/resources/follow.rb +42 -0
  27. data/lib/whatser/resources/media.rb +41 -0
  28. data/lib/whatser/resources/poi.rb +74 -0
  29. data/lib/whatser/resources/resource.rb +53 -0
  30. data/lib/whatser/resources/review.rb +40 -0
  31. data/lib/whatser/resources/subscription.rb +12 -0
  32. data/lib/whatser/resources/tag.rb +32 -0
  33. data/lib/whatser/resources/user.rb +81 -0
  34. data/lib/whatser.rb +38 -0
  35. data/test/helper.rb +25 -0
  36. data/test/test_activity_feed.rb +20 -0
  37. data/test/test_check_in.rb +28 -0
  38. data/test/test_city.rb +16 -0
  39. data/test/test_client.rb +84 -0
  40. data/test/test_collection.rb +28 -0
  41. data/test/test_configuration.rb +26 -0
  42. data/test/test_data_source.rb +35 -0
  43. data/test/test_detail.rb +38 -0
  44. data/test/test_facebook.rb +7 -0
  45. data/test/test_follow.rb +33 -0
  46. data/test/test_foursquare.rb +7 -0
  47. data/test/test_gowalla.rb +7 -0
  48. data/test/test_hondius.rb +12 -0
  49. data/test/test_http.rb +40 -0
  50. data/test/test_oauth.rb +37 -0
  51. data/test/test_poi.rb +75 -0
  52. data/test/test_resource.rb +73 -0
  53. data/test/test_response.rb +44 -0
  54. data/test/test_review.rb +37 -0
  55. data/test/test_subscription.rb +11 -0
  56. data/test/test_tag.rb +32 -0
  57. data/test/test_twitter.rb +7 -0
  58. data/test/test_user.rb +53 -0
  59. data/whatser.gemspec +140 -0
  60. metadata +236 -0
data/test/helper.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'whatser'
15
+
16
+ class Test::Unit::TestCase
17
+ end
18
+
19
+ module Whatser
20
+ module Http
21
+ def request(verb, path, options={})
22
+ Whatser::Response.new('')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ class TestActivityFeed < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser::Client.new(:oauth_token => '1234')
6
+ @user_id = 1
7
+ end
8
+
9
+ def test_my_feed
10
+ assert @client.feeds.mine( :page => 1, :per_page => 10 ).is_a?(Whatser::Response)
11
+ end
12
+
13
+ def test_user_feed
14
+ assert @client.feeds.user( @user_id, :page => 1, :per_page => 10 ).is_a?(Whatser::Response)
15
+ end
16
+
17
+ def test_global_feed
18
+ assert @client.feeds.global( :page => 1, :per_page => 10 ).is_a?(Whatser::Response)
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestPoi < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser::Client.new
6
+ @poi_id = 1
7
+ @check_in = Whatser::CheckIn.new(:poi_id => @poi_id)
8
+ end
9
+
10
+ def test_list
11
+ assert @client.check_ins.list(:page => @poi_id).is_a?(Whatser::Response)
12
+ end
13
+
14
+ def test_create
15
+ assert @client.check_ins.create(@poi_id, :check_in_at => Time.now).is_a?(Whatser::Response)
16
+ end
17
+
18
+ def test_save
19
+ assert @check_in.save.is_a?(Whatser::Response)
20
+ end
21
+
22
+ def test_to_params
23
+ params = [:locate,:lat,:lng,:gowalla,:foursquare,:check_in_at,:check_out_at]
24
+ params.each do |p|
25
+ assert @check_in.to_params.keys.include?(p)
26
+ end
27
+ end
28
+ end
data/test/test_city.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class TestCity < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser::Client.new(:oauth_token => '1234')
6
+ @user_id = 1
7
+ end
8
+
9
+ def test_my_cities
10
+ assert @client.cities.mine( :page => 1, :per_page => 10 ).is_a?(Whatser::Response)
11
+ end
12
+
13
+ def test_user_cities
14
+ assert @client.cities.user( @user_id, :page => 1, :per_page => 10 ).is_a?(Whatser::Response)
15
+ end
16
+ end
@@ -0,0 +1,84 @@
1
+ require 'helper'
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+ def test_attr_accessor
5
+ client = Whatser::Client.new
6
+ Whatser::Configuration::VALID_OPTIONS_KEYS.each do |a|
7
+ assert client.respond_to?(a)
8
+ end
9
+ end
10
+
11
+ def test_cattr_accessor
12
+ Whatser::Configuration::VALID_OPTIONS_KEYS.each do |a|
13
+ assert Whatser::Client.respond_to?(a)
14
+ end
15
+ end
16
+
17
+ def test_initialize_with_options
18
+ params = {:api_key => '123',
19
+ :api_secret => 'abc',
20
+ :oauth_token => 'xyz',
21
+ :api_uri => 'www.example.com',
22
+ :username => 'test@example.com',
23
+ :password => 'test'}
24
+
25
+ client = Whatser::Client.new( params )
26
+ assert_equal params[:api_key], client.api_key
27
+ assert_equal params[:api_secret], client.api_secret
28
+ assert_equal params[:username], client.username
29
+ assert_equal params[:password], client.password
30
+ end
31
+
32
+ def test_initialize_with_configure_defaults
33
+ Whatser::Client.configure do |config|
34
+ config.api_key = 'key'
35
+ config.api_secret = 'secret'
36
+ config.oauth_token = '123abc'
37
+ end
38
+ client = Whatser::Client.new
39
+ assert_equal 'key', client.api_key
40
+ assert_equal 'secret', client.api_secret
41
+ assert_equal '123abc', client.oauth_token
42
+ end
43
+
44
+ def test_resources
45
+ client = Whatser::Client.new
46
+ assert_equal Whatser::CheckIn, client.check_ins
47
+ assert_equal Whatser::Collection, client.collections
48
+ assert_equal Whatser::DataSource, client.data_sources
49
+ assert_equal Whatser::Detail, client.details
50
+ assert_equal Whatser::Media, client.media
51
+ assert_equal Whatser::Poi, client.spots
52
+ assert_equal Whatser::Subscription, client.subscriptions
53
+ assert_equal Whatser::Tag, client.tags
54
+ assert_equal Whatser::User, client.users
55
+ assert_equal Whatser::Follow, client.follows
56
+ assert_equal Whatser::Facebook, client.facebook
57
+ assert_equal Whatser::Foursquare, client.foursquare
58
+ assert_equal Whatser::Gowalla, client.gowalla
59
+ assert_equal Whatser::Twitter, client.twitter
60
+
61
+ assert_equal client, client.check_ins.client
62
+ assert_equal client, client.collections.client
63
+ assert_equal client, client.data_sources.client
64
+ assert_equal client, client.details.client
65
+ assert_equal client, client.media.client
66
+ assert_equal client, client.spots.client
67
+ assert_equal client, client.subscriptions.client
68
+ assert_equal client, client.tags.client
69
+ assert_equal client, client.users.client
70
+ assert_equal client, client.follows.client
71
+ assert_equal client, client.facebook.client
72
+ assert_equal client, client.foursquare.client
73
+ assert_equal client, client.gowalla.client
74
+ assert_equal client, client.twitter.client
75
+ end
76
+
77
+ def test_authorized
78
+ client = Whatser::Client.new
79
+ assert_equal false, client.authorized?
80
+
81
+ client.oauth_token = 'test'
82
+ assert_equal true, client.authorized?
83
+ end
84
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestCollection < Test::Unit::TestCase
4
+ def setup
5
+ @data = [1,2,3]
6
+ end
7
+
8
+ def test_initialize
9
+ collection = Whatser::Collection.new(@data)
10
+ assert_equal @data, collection.data
11
+ end
12
+
13
+ def test_each_enumerable
14
+ iterated = []
15
+ collection = Whatser::Collection.new(@data)
16
+ collection.each do |c|
17
+ iterated << c
18
+ end
19
+ assert_equal @data, iterated
20
+ end
21
+
22
+ def test_size
23
+ collection = Whatser::Collection.new
24
+ assert_equal 0, collection.size
25
+ collection.data = @data
26
+ assert_equal @data.size, collection.size
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ class TestConfiguration < Test::Unit::TestCase
4
+ def reset_defaults
5
+ Whatser::Client.configure do |config|
6
+ config.api_key = nil
7
+ config.api_secret = nil
8
+ config.oauth_token = nil
9
+ end
10
+ end
11
+
12
+ def test_valid_options_keys
13
+ expected = [:api_key,:api_secret,:username,:password,:oauth_token,:api_uri,:redirect_uri]
14
+ assert_equal expected, Whatser::Configuration::VALID_OPTIONS_KEYS
15
+ end
16
+
17
+ def test_defaults_on_inclusion
18
+ reset_defaults
19
+ client = Whatser::Client.new
20
+ assert_equal nil, client.api_key
21
+ assert_equal nil, client.api_secret
22
+ assert_equal nil, client.oauth_token
23
+ assert_equal nil, client.redirect_uri
24
+ assert_equal Whatser::Configuration::DEFAULT_API_URI, client.api_uri
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ class TestDataSource < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser::Client.new(:oauth_token => '1234')
6
+ end
7
+
8
+ def test_list
9
+ assert @client.data_sources.list(:page => 1).is_a?(Whatser::Response)
10
+ end
11
+
12
+ def test_for_users_with_id
13
+ assert @client.data_sources.for_users(1, :page => 1).is_a?(Whatser::Response)
14
+ end
15
+
16
+ def test_for_users_with_string
17
+ assert @client.data_sources.for_users('1,2,3', :page => 1).is_a?(Whatser::Response)
18
+ end
19
+
20
+ def test_for_users_with_array
21
+ assert @client.data_sources.for_users([1,2,3], :page => 1).is_a?(Whatser::Response)
22
+ end
23
+
24
+ def test_subscription_url
25
+ datasource = @client.data_sources.new(:id => '1')
26
+ expected = "#{@client.api_uri}/payments/data_sources/1/orders/new?oauth_token=1234"
27
+ assert_equal expected, datasource.subscription_url
28
+ end
29
+
30
+ def test_subscription_url_with_params
31
+ datasource = @client.data_sources.new(:id => '1')
32
+ expected = "#{@client.api_uri}/payments/data_sources/1/orders/new?oauth_token=1234&test=2&extra=1"
33
+ assert_equal expected, datasource.subscription_url(:extra => 1, :test => 2)
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ class TestDetail < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser::Client.new
6
+ @poi_id = 1
7
+ @params = {:rating => 'four stars', :hours => '9-5'}
8
+ @detail = Whatser::Detail.new(:poi_id => @poi_id, :data => @params)
9
+ end
10
+
11
+ def test_list
12
+ assert @client.reviews.list(@poi_id, :page => 1).is_a?(Whatser::Response)
13
+ end
14
+
15
+ def test_create
16
+ assert @client.reviews.create(@poi_id, :data => @params).is_a?(Whatser::Response)
17
+ end
18
+
19
+ def test_delete
20
+ assert @client.reviews.delete(@poi_id, :data => @params).is_a?(Whatser::Response)
21
+ end
22
+
23
+ def test_save
24
+ assert @detail.save.is_a?(Whatser::Response)
25
+ end
26
+
27
+ def test_update
28
+ @detail.id = 1
29
+ assert @detail.save.is_a?(Whatser::Response)
30
+ end
31
+
32
+ def test_to_params
33
+ params = [:data]
34
+ params.each do |p|
35
+ assert @detail.to_params.keys.include?(p)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFacebook < Test::Unit::TestCase
4
+ def test_key
5
+ assert_equal 'facebook', Whatser::Facebook.new.key
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ class TestFollow < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser::Client.new
6
+ @user_id = 1
7
+ @follow = Whatser::Follow.new(:id => @user_id)
8
+ end
9
+
10
+ def test_list
11
+ assert @client.follows.list(:page => 1).is_a?(Whatser::Response)
12
+ end
13
+
14
+ def test_suggested
15
+ assert @client.follows.suggested(:page => 1).is_a?(Whatser::Response)
16
+ end
17
+
18
+ def test_create
19
+ assert @client.follows.create(@user_id).is_a?(Whatser::Response)
20
+ end
21
+
22
+ def test_delete
23
+ assert @client.follows.delete(@user_id).is_a?(Whatser::Response)
24
+ end
25
+
26
+ def test_ignore
27
+ assert @client.follows.ignore(@user_id).is_a?(Whatser::Response)
28
+ end
29
+
30
+ def test_save
31
+ assert @follow.save.is_a?(Whatser::Response)
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFoursquare < Test::Unit::TestCase
4
+ def test_key
5
+ assert_equal 'foursquare', Whatser::Foursquare.new.key
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGowalla < Test::Unit::TestCase
4
+ def test_key
5
+ assert_equal 'gowalla', Whatser::Gowalla.new.key
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+
3
+ class TestWhatser < Test::Unit::TestCase
4
+ def test_client
5
+ assert Whatser.client.is_a?( Whatser::Client )
6
+ end
7
+
8
+ def test_client_cached
9
+ client = Whatser.client
10
+ assert_equal client.object_id, Whatser.client.object_id
11
+ end
12
+ end
data/test/test_http.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+
3
+ class TestHttp < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser.client
6
+ end
7
+
8
+ def test_request_options_default
9
+ @client.oauth_token = '123'
10
+ expected = {:query => {:oauth_token => '123'}, :body => nil}
11
+ assert_equal expected, @client.send(:request_options)
12
+ end
13
+
14
+ def test_request_options_with_query
15
+ @client.oauth_token = '123'
16
+ expected = {:query => {:oauth_token => '123', :extra => 1}, :body => nil}
17
+ assert_equal expected, @client.send(:request_options, {:query => {:extra => 1} })
18
+ end
19
+
20
+ def test_request_options_with_body
21
+ @client.oauth_token = '123'
22
+ expected = {:query => {:oauth_token => '123'}, :body => {:extra => 1}}
23
+ assert_equal expected, @client.send(:request_options, {:body => {:extra => 1} })
24
+ end
25
+
26
+ def test_base_uri_on_included
27
+ assert_equal @client.api_uri, Whatser::Http.base_uri
28
+ end
29
+
30
+ def test_request
31
+ response = @client.request(:get, '/', {})
32
+ assert response.is_a?(Whatser::Response)
33
+ end
34
+
35
+ def test_compose_url
36
+ path = '/api/endpoint'
37
+ uri = @client.api_uri
38
+ assert_equal "#{uri}#{path}", @client.send(:compose_url, path)
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ class TestOauth < Test::Unit::TestCase
4
+ def test_oauth_client
5
+ params = {:api_key => '123', :api_secret => '123', :api_uri => 'http://example.com'}
6
+ client = Whatser::Client.new(params)
7
+ oauth = client.oauth_client
8
+ assert oauth.is_a?(OAuth2::Client)
9
+ assert_equal params[:api_key], oauth.id
10
+ assert_equal params[:api_secret], oauth.secret
11
+ assert_equal params[:api_uri], oauth.site
12
+ end
13
+
14
+ def test_oauth_authorize_url
15
+ base = 'http://example.com/oauth/authorize'
16
+ client = Whatser::Client.new(:api_uri => base, :api_key => '123')
17
+ assert_equal "#{base}?client_id=123&type=web_server", client.oauth_authorize_url
18
+ assert_equal "#{base}?client_id=123&type=web_server&redirect_uri=http%3A%2F%2Fexample.com%2Foauth%2Fauthorize", client.oauth_authorize_url(:redirect_uri => base)
19
+ end
20
+
21
+ def test_hash_to_query
22
+ client = Whatser::Client.new
23
+ assert_equal ["first=1","second=2"].sort, client.send(:hash_to_query, {:first => 1, :second => 2}).split('&').sort
24
+ assert_equal "", client.send(:hash_to_query, {} )
25
+ end
26
+
27
+ def test_password_grant_params
28
+ params = {:api_key => '123', :api_secret => '123', :api_uri => 'http://example.com'}
29
+ client = Whatser::Client.new(params)
30
+ expected = {'grant_type' => 'password',
31
+ 'client_id' => '123',
32
+ 'client_secret' => '123',
33
+ 'username' => 'mail',
34
+ 'password' => 'pw'}
35
+ assert_equal expected, client.send(:password_grant_params, 'mail', 'pw')
36
+ end
37
+ end
data/test/test_poi.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'helper'
2
+
3
+ class TestPoi < Test::Unit::TestCase
4
+ def setup
5
+ @client = Whatser::Client.new
6
+ @poi = Whatser::Poi.new
7
+ end
8
+
9
+ def test_to_params
10
+ poi = Whatser::Poi.new
11
+ params = [:name,:lat,:lng,:street,:district,:region,:city,:postal_code,:country]
12
+ params.each do |p|
13
+ assert poi.to_params.keys.include?(p)
14
+ end
15
+ end
16
+
17
+ def test_suggested
18
+ assert @client.spots.suggested(:opt => 'test').is_a?(Whatser::Response)
19
+ end
20
+
21
+ def test_search
22
+ assert @client.spots.search(:opt => 'test').is_a?(Whatser::Response)
23
+ end
24
+
25
+ def test_find
26
+ assert @client.spots.find(1, :opt => 'test').is_a?(Whatser::Response)
27
+ end
28
+
29
+ def test_create
30
+ assert @client.spots.create(:name => 'test', :lat => 45, :lng => 45).is_a?(Whatser::Response)
31
+ end
32
+
33
+ def test_delete
34
+ assert @client.spots.delete(1).is_a?(Whatser::Response)
35
+ end
36
+
37
+ def test_save
38
+ assert @poi.save.is_a?(Whatser::Response)
39
+ end
40
+
41
+ def test_save_and_update
42
+ @poi.id = 1
43
+ assert @poi.save.is_a?(Whatser::Response)
44
+ end
45
+
46
+ def test_from_hash_to_model
47
+ hash = {'id' => 1, 'name' => 'test', 'lat' => 1, 'lng' => 1, 'street' => 'test',
48
+ 'district' => 'test', 'region' => 'test', 'city' => 'test', 'postal_code' => '1', 'country' => 'test'}
49
+ poi = Whatser::Poi.from_hash_to_model(hash)
50
+ assert poi.is_a?(Whatser::Poi)
51
+
52
+ assert_equal hash['id'], poi.id
53
+ assert_equal hash['name'], poi.name
54
+ assert_equal hash['lat'], poi.lat
55
+ assert_equal hash['lng'], poi.lng
56
+ assert_equal hash['street'], poi.street
57
+ assert_equal hash['district'], poi.district
58
+ assert_equal hash['region'], poi.region
59
+ assert_equal hash['city'], poi.city
60
+ assert_equal hash['postal_code'], poi.postal_code
61
+ assert_equal hash['country'], poi.country
62
+ end
63
+
64
+ def foursquare_connected
65
+ assert_equal false, @poi.foursquare_connected?
66
+ @poi.foursquare_id = 1
67
+ assert_equal true, @poi.foursquare_connected?
68
+ end
69
+
70
+ def gowalla_connected
71
+ assert_equal false, @poi.foursquare_connected?
72
+ @poi.foursquare_id = 1
73
+ assert_equal true, @poi.foursquare_connected?
74
+ end
75
+ end
@@ -0,0 +1,73 @@
1
+ require 'helper'
2
+
3
+ class TestResource < Test::Unit::TestCase
4
+ def test_client
5
+ client = Whatser::Client.new
6
+ Whatser::Resource.instance_variable_set('@client',client)
7
+ assert_equal client, Whatser::Resource.client
8
+ end
9
+
10
+ def test_set_client
11
+ client = Whatser::Client.new
12
+ res = Whatser::Resource.set(client)
13
+ assert_equal res.client, client
14
+ end
15
+
16
+ def test_convert_data_to_model_with_blank
17
+ res = Whatser::Resource
18
+ assert_nil res.convert_data_to_model(nil)
19
+ assert_equal [], res.convert_data_to_model([])
20
+ end
21
+
22
+ def test_convert_data_to_model_with_hash
23
+ res = Whatser::Resource
24
+ mod = res.convert_data_to_model(:test => '1', :testing => '1')
25
+ assert mod.is_a?(Whatser::Resource)
26
+ end
27
+
28
+ def test_convert_data_to_model_with_array
29
+ res = Whatser::Resource
30
+ arr = res.convert_data_to_model([{:test => '1', :testing => '1'},{:test => '2', :testing => '1'}])
31
+ arr.each do |mod|
32
+ assert mod.is_a?(Whatser::Resource)
33
+ end
34
+ end
35
+
36
+ def test_api_request
37
+ Whatser::Resource.set( Whatser.client )
38
+ resource = Whatser::Resource
39
+ response = resource.api_request(:get, '/path', {})
40
+ assert response.is_a?(Whatser::Response)
41
+ end
42
+
43
+ def test_instance_api_request
44
+ Whatser::Resource.set( Whatser.client )
45
+ resource = Whatser::Resource.new
46
+ response = resource.api_request(:get, '/path', {})
47
+ assert response.is_a?(Whatser::Response)
48
+ end
49
+
50
+ def test_from_hash_to_model
51
+ hash = {:test => '1', :testing => '1'}
52
+ mod = Whatser::Resource.from_hash_to_model(hash)
53
+ assert mod.is_a?(Whatser::Resource)
54
+ end
55
+
56
+ def test_from_hash_to_model_with_root
57
+ hash = {:root => {:test => '1', :testing => '1'}}
58
+ mod = Whatser::Resource.from_hash_to_model(hash)
59
+ assert mod.is_a?(Whatser::Resource)
60
+ end
61
+
62
+ def test_from_hash_to_model_with_option
63
+ hash = {:id => '1', :name => 'Test'}
64
+ option = Whatser::Poi
65
+ mod = Whatser::Resource.from_hash_to_model(hash, option)
66
+ assert mod.is_a?(Whatser::Poi)
67
+ end
68
+
69
+ def test_from_hash_to_model_empty
70
+ mod = Whatser::Resource.from_hash_to_model(nil)
71
+ assert mod.is_a?(Whatser::Resource)
72
+ end
73
+ end
@@ -0,0 +1,44 @@
1
+ require 'helper'
2
+
3
+ class TestResponse < Test::Unit::TestCase
4
+ def test_initialize
5
+ res = Whatser::Response.new({})
6
+ assert_equal nil, res.data
7
+ res = Whatser::Response.new( {'data' => []} )
8
+ assert_equal [], res.data
9
+ end
10
+
11
+ def test_load_from_hash
12
+ params = {'data'=>'test1','http_status'=>'test2','version'=>'test3','scope'=>'test4','page'=>'test5','per_page'=>'test6','more'=>'test7','error'=>'test8','error_description'=>'test9','error_uri'=>'test0'}
13
+ res = Whatser::Response.new({})
14
+ res.load_from_hash(params)
15
+ assert_equal params['data'], res.data
16
+ assert_equal params['http_status'], res.http_status
17
+ assert_equal params['version'], res.version
18
+ assert_equal params['scope'], res.scope
19
+ assert_equal params['page'], res.page
20
+ assert_equal params['per_page'], res.per_page
21
+ assert_equal params['more'], res.more
22
+ assert_equal params['error'], res.error
23
+ assert_equal params['error_description'], res.error_description
24
+ assert_equal params['error_uri'], res.error_uri
25
+ end
26
+
27
+ def test_data_enum
28
+ res = Whatser::Response.new({})
29
+ assert_equal [], res.data_enum
30
+ res.data = "test"
31
+ assert_equal ["test"], res.data_enum
32
+ res.data = [1,2,3]
33
+ assert_equal [1,2,3], res.data_enum
34
+ end
35
+
36
+ def test_each
37
+ res = Whatser::Response.new({})
38
+ res.data = [1,2,3]
39
+ assert res.respond_to?(:each)
40
+ res.each_with_index do |e,idx|
41
+ assert_equal res.data[idx], e
42
+ end
43
+ end
44
+ end