palidanx-koala 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ require 'erb'
2
+ require 'yaml'
3
+
4
+ module Koala
5
+ module MockHTTPService
6
+ # Mocks all HTTP requests for with koala_spec_with_mocks.rb
7
+
8
+ # Mocked values to be included in TEST_DATA used in specs
9
+ ACCESS_TOKEN = '*'
10
+ OAUTH_CODE = 'OAUTHCODE'
11
+
12
+ # Loads testing data
13
+ TEST_DATA = YAML.load_file(File.join(File.dirname(__FILE__), 'facebook_data.yml'))
14
+ TEST_DATA.merge!('oauth_token' => Koala::MockHTTPService::ACCESS_TOKEN)
15
+ TEST_DATA['oauth_test_data'].merge!('code' => Koala::MockHTTPService::OAUTH_CODE)
16
+
17
+ # Useful in mock_facebook_responses.yml
18
+ OAUTH_DATA = TEST_DATA['oauth_test_data']
19
+ OAUTH_DATA.merge!({
20
+ 'app_access_token' => Koala::MockHTTPService::ACCESS_TOKEN,
21
+ 'session_key' => "session_key",
22
+ 'multiple_session_keys' => ["session_key", "session_key_2"]
23
+ })
24
+ APP_ID = OAUTH_DATA['app_id']
25
+ SECRET = OAUTH_DATA['secret']
26
+ SUBSCRIPTION_DATA = TEST_DATA["subscription_test_data"]
27
+
28
+ # Loads the mock response data via ERB to substitue values for TEST_DATA (see oauth/access_token)
29
+ mock_response_file_path = File.join(File.dirname(__FILE__), 'mock_facebook_responses.yml')
30
+ RESPONSES = YAML.load(ERB.new(IO.read(mock_response_file_path)).result(binding))
31
+
32
+ def self.included(base)
33
+ base.class_eval do
34
+
35
+ def self.make_request(path, args, verb, options = {})
36
+ path = 'root' if path == '' || path == '/'
37
+ verb ||= 'get'
38
+ server = options[:rest_api] ? 'rest_api' : 'graph_api'
39
+ with_token = args.delete('access_token') == ACCESS_TOKEN ? 'with_token' : 'no_token'
40
+
41
+ # Assume format is always JSON
42
+ args.delete('format')
43
+
44
+ # Create a hash key for the arguments
45
+ args = args.empty? ? 'no_args' : args.sort{|a,b| a[0].to_s <=> b[0].to_s }.map{|arr| arr.join('=')}.join('&')
46
+
47
+ begin
48
+ response = RESPONSES[server][path][args][verb][with_token]
49
+
50
+ # Raises an error of with_token/no_token key is missing
51
+ raise NoMethodError unless response
52
+
53
+ # create response class object
54
+ response_object = if response.is_a? String
55
+ Koala::Response.new(200, response, {})
56
+ else
57
+ Koala::Response.new(response["code"] || 200, response["body"] || "", response["headers"] || {})
58
+ end
59
+
60
+ rescue NoMethodError
61
+ # Raises an error message with the place in the data YML
62
+ # to place a mock as well as a URL to request from
63
+ # Facebook's servers for the actual data
64
+ # (Don't forget to replace ACCESS_TOKEN with a real access token)
65
+
66
+ data_trace = [server, path, args, verb, with_token] * ': '
67
+
68
+ args = args == 'no_args' ? '' : "#{args}&"
69
+ args += 'format=json'
70
+ args += "&access_token=#{ACCESS_TOKEN}" if with_token
71
+
72
+ raise "Missing a mock response for #{data_trace}\nAPI PATH: #{[path, args].join('?')}"
73
+ end
74
+
75
+ response_object
76
+ end
77
+
78
+ end # class_eval
79
+ end # included
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: palidanx-koala
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 0
9
+ version: 0.9.0
10
+ platform: ruby
11
+ authors:
12
+ - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-29 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.
22
+ email: alex@alexkoppel.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - CHANGELOG
29
+ - LICENSE
30
+ - lib/koala.rb
31
+ - lib/koala/graph_api.rb
32
+ - lib/koala/http_services.rb
33
+ - lib/koala/realtime_updates.rb
34
+ - lib/koala/rest_api.rb
35
+ files:
36
+ - CHANGELOG
37
+ - LICENSE
38
+ - Manifest
39
+ - Rakefile
40
+ - init.rb
41
+ - koala.gemspec
42
+ - lib/koala.rb
43
+ - lib/koala/graph_api.rb
44
+ - lib/koala/http_services.rb
45
+ - lib/koala/realtime_updates.rb
46
+ - lib/koala/rest_api.rb
47
+ - readme.md
48
+ - spec/facebook_data.yml
49
+ - spec/koala/api_base_tests.rb
50
+ - spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb
51
+ - spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb
52
+ - spec/koala/graph_api/graph_api_no_access_token_tests.rb
53
+ - spec/koala/graph_api/graph_api_with_access_token_tests.rb
54
+ - spec/koala/live_testing_data_helper.rb
55
+ - spec/koala/net_http_service_tests.rb
56
+ - spec/koala/oauth/oauth_tests.rb
57
+ - spec/koala/realtime_updates/realtime_updates_tests.rb
58
+ - spec/koala/rest_api/rest_api_no_access_token_tests.rb
59
+ - spec/koala/rest_api/rest_api_with_access_token_tests.rb
60
+ - spec/koala_spec.rb
61
+ - spec/koala_spec_helper.rb
62
+ - spec/koala_spec_without_mocks.rb
63
+ - spec/mock_facebook_responses.yml
64
+ - spec/mock_http_service.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/palidanx/koala
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --line-numbers
72
+ - --inline-source
73
+ - --title
74
+ - Koala
75
+ - --main
76
+ - readme.md
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 1
92
+ - 2
93
+ version: "1.2"
94
+ requirements: []
95
+
96
+ rubyforge_project: koala
97
+ rubygems_version: 1.3.6
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation.
101
+ test_files: []
102
+