koala 1.0.0 → 1.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.
Files changed (54) hide show
  1. data/.autotest +12 -0
  2. data/.gitignore +3 -1
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +62 -2
  5. data/Gemfile +8 -0
  6. data/Rakefile +0 -1
  7. data/autotest/discover.rb +1 -0
  8. data/koala.gemspec +13 -14
  9. data/lib/koala/batch_operation.rb +74 -0
  10. data/lib/koala/graph_api.rb +145 -132
  11. data/lib/koala/graph_batch_api.rb +97 -0
  12. data/lib/koala/graph_collection.rb +59 -0
  13. data/lib/koala/http_service.rb +176 -0
  14. data/lib/koala/oauth.rb +191 -0
  15. data/lib/koala/realtime_updates.rb +23 -29
  16. data/lib/koala/rest_api.rb +13 -8
  17. data/lib/koala/test_users.rb +33 -17
  18. data/lib/koala/uploadable_io.rb +153 -87
  19. data/lib/koala/utils.rb +11 -0
  20. data/lib/koala/version.rb +3 -0
  21. data/lib/koala.rb +59 -217
  22. data/readme.md +92 -53
  23. data/spec/cases/{api_base_spec.rb → api_spec.rb} +31 -6
  24. data/spec/cases/error_spec.rb +32 -0
  25. data/spec/cases/graph_and_rest_api_spec.rb +12 -21
  26. data/spec/cases/graph_api_batch_spec.rb +582 -0
  27. data/spec/cases/graph_api_spec.rb +11 -14
  28. data/spec/cases/graph_collection_spec.rb +116 -0
  29. data/spec/cases/http_service_spec.rb +446 -0
  30. data/spec/cases/koala_spec.rb +54 -0
  31. data/spec/cases/oauth_spec.rb +319 -213
  32. data/spec/cases/realtime_updates_spec.rb +45 -31
  33. data/spec/cases/rest_api_spec.rb +23 -7
  34. data/spec/cases/test_users_spec.rb +123 -75
  35. data/spec/cases/uploadable_io_spec.rb +120 -37
  36. data/spec/cases/utils_spec.rb +10 -0
  37. data/spec/fixtures/cat.m4v +0 -0
  38. data/spec/fixtures/facebook_data.yml +26 -24
  39. data/spec/fixtures/mock_facebook_responses.yml +203 -78
  40. data/spec/spec_helper.rb +30 -5
  41. data/spec/support/graph_api_shared_examples.rb +149 -118
  42. data/spec/support/json_testing_fix.rb +42 -0
  43. data/spec/support/koala_test.rb +187 -0
  44. data/spec/support/mock_http_service.rb +62 -58
  45. data/spec/support/ordered_hash.rb +205 -0
  46. data/spec/support/rest_api_shared_examples.rb +139 -15
  47. data/spec/support/uploadable_io_shared_examples.rb +2 -8
  48. metadata +90 -114
  49. data/lib/koala/http_services.rb +0 -146
  50. data/spec/cases/http_services/http_service_spec.rb +0 -54
  51. data/spec/cases/http_services/net_http_service_spec.rb +0 -350
  52. data/spec/cases/http_services/typhoeus_service_spec.rb +0 -144
  53. data/spec/support/live_testing_data_helper.rb +0 -40
  54. data/spec/support/setup_mocks_or_live.rb +0 -52
metadata CHANGED
@@ -1,202 +1,178 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: koala
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-01 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-09-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: &70248641333480 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
18
+ requirements:
25
19
  - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 15
28
- segments:
29
- - 1
30
- - 0
31
- version: "1.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
32
22
  type: :runtime
33
- name: json
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70248641333480
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &70248641333000 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
29
+ requirements:
40
30
  - - ~>
41
- - !ruby/object:Gem::Version
42
- hash: 15
43
- segments:
44
- - 1
45
- - 0
46
- version: "1.0"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.0
47
33
  type: :runtime
48
- name: multipart-post
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70248641333000
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70248641332520 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
40
+ requirements:
55
41
  - - ~>
56
- - !ruby/object:Gem::Version
57
- hash: 27
58
- segments:
59
- - 2
60
- - 5
61
- - 0
62
- version: 2.5.0
42
+ - !ruby/object:Gem::Version
43
+ version: '2.5'
63
44
  type: :development
64
- name: rspec
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
45
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70248641332520
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70248641332040 !ruby/object:Gem::Requirement
69
50
  none: false
70
- requirements:
51
+ requirements:
71
52
  - - ~>
72
- - !ruby/object:Gem::Version
73
- hash: 49
74
- segments:
75
- - 0
76
- - 8
77
- - 7
53
+ - !ruby/object:Gem::Version
78
54
  version: 0.8.7
79
55
  type: :development
80
- name: rake
81
- version_requirements: *id004
82
- - !ruby/object:Gem::Dependency
83
56
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- hash: 31
90
- segments:
91
- - 0
92
- - 2
93
- - 4
94
- version: 0.2.4
95
- type: :development
96
- name: typhoeus
97
- version_requirements: *id005
98
- description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph and REST APIs, 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.
57
+ version_requirements: *70248641332040
58
+ description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write
59
+ access to the social graph via the Graph and REST APIs, as well as support for realtime
60
+ updates and OAuth and Facebook Connect authentication. Koala is fully tested and
61
+ supports Net::HTTP and Typhoeus connections out of the box and can accept custom
62
+ modules for other services.
99
63
  email: alex@alexkoppel.com
100
64
  executables: []
101
-
102
65
  extensions: []
103
-
104
- extra_rdoc_files:
66
+ extra_rdoc_files:
105
67
  - readme.md
106
68
  - CHANGELOG
107
- files:
69
+ files:
70
+ - .autotest
108
71
  - .gitignore
72
+ - .travis.yml
109
73
  - CHANGELOG
110
74
  - Gemfile
111
75
  - LICENSE
112
76
  - Manifest
113
77
  - Rakefile
78
+ - autotest/discover.rb
114
79
  - koala.gemspec
115
80
  - lib/koala.rb
81
+ - lib/koala/batch_operation.rb
116
82
  - lib/koala/graph_api.rb
117
- - lib/koala/http_services.rb
83
+ - lib/koala/graph_batch_api.rb
84
+ - lib/koala/graph_collection.rb
85
+ - lib/koala/http_service.rb
86
+ - lib/koala/oauth.rb
118
87
  - lib/koala/realtime_updates.rb
119
88
  - lib/koala/rest_api.rb
120
89
  - lib/koala/test_users.rb
121
90
  - lib/koala/uploadable_io.rb
91
+ - lib/koala/utils.rb
92
+ - lib/koala/version.rb
122
93
  - readme.md
123
- - spec/cases/api_base_spec.rb
94
+ - spec/cases/api_spec.rb
95
+ - spec/cases/error_spec.rb
124
96
  - spec/cases/graph_and_rest_api_spec.rb
97
+ - spec/cases/graph_api_batch_spec.rb
125
98
  - spec/cases/graph_api_spec.rb
126
- - spec/cases/http_services/http_service_spec.rb
127
- - spec/cases/http_services/net_http_service_spec.rb
128
- - spec/cases/http_services/typhoeus_service_spec.rb
99
+ - spec/cases/graph_collection_spec.rb
100
+ - spec/cases/http_service_spec.rb
101
+ - spec/cases/koala_spec.rb
129
102
  - spec/cases/oauth_spec.rb
130
103
  - spec/cases/realtime_updates_spec.rb
131
104
  - spec/cases/rest_api_spec.rb
132
105
  - spec/cases/test_users_spec.rb
133
106
  - spec/cases/uploadable_io_spec.rb
107
+ - spec/cases/utils_spec.rb
134
108
  - spec/fixtures/beach.jpg
109
+ - spec/fixtures/cat.m4v
135
110
  - spec/fixtures/facebook_data.yml
136
111
  - spec/fixtures/mock_facebook_responses.yml
137
112
  - spec/spec_helper.rb
138
113
  - spec/support/graph_api_shared_examples.rb
139
- - spec/support/live_testing_data_helper.rb
114
+ - spec/support/json_testing_fix.rb
115
+ - spec/support/koala_test.rb
140
116
  - spec/support/mock_http_service.rb
117
+ - spec/support/ordered_hash.rb
141
118
  - spec/support/rest_api_shared_examples.rb
142
- - spec/support/setup_mocks_or_live.rb
143
119
  - spec/support/uploadable_io_shared_examples.rb
144
120
  homepage: http://github.com/arsduo/koala
145
121
  licenses: []
146
-
147
122
  post_install_message:
148
- rdoc_options:
123
+ rdoc_options:
149
124
  - --line-numbers
150
125
  - --inline-source
151
126
  - --title
152
127
  - Koala
153
- require_paths:
128
+ require_paths:
154
129
  - lib
155
- required_ruby_version: !ruby/object:Gem::Requirement
130
+ required_ruby_version: !ruby/object:Gem::Requirement
156
131
  none: false
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- hash: 3
161
- segments:
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ segments:
162
137
  - 0
163
- version: "0"
164
- required_rubygems_version: !ruby/object:Gem::Requirement
138
+ hash: 2837078681376474267
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
140
  none: false
166
- requirements:
167
- - - ">="
168
- - !ruby/object:Gem::Version
169
- hash: 11
170
- segments:
171
- - 1
172
- - 2
173
- version: "1.2"
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '1.2'
174
145
  requirements: []
175
-
176
146
  rubyforge_project:
177
- rubygems_version: 1.7.2
147
+ rubygems_version: 1.8.8
178
148
  signing_key:
179
149
  specification_version: 3
180
- summary: A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.
181
- test_files:
182
- - spec/cases/api_base_spec.rb
150
+ summary: A lightweight, flexible library for Facebook with support for the Graph API,
151
+ the REST API, realtime updates, and OAuth authentication.
152
+ test_files:
153
+ - spec/cases/api_spec.rb
154
+ - spec/cases/error_spec.rb
183
155
  - spec/cases/graph_and_rest_api_spec.rb
156
+ - spec/cases/graph_api_batch_spec.rb
184
157
  - spec/cases/graph_api_spec.rb
185
- - spec/cases/http_services/http_service_spec.rb
186
- - spec/cases/http_services/net_http_service_spec.rb
187
- - spec/cases/http_services/typhoeus_service_spec.rb
158
+ - spec/cases/graph_collection_spec.rb
159
+ - spec/cases/http_service_spec.rb
160
+ - spec/cases/koala_spec.rb
188
161
  - spec/cases/oauth_spec.rb
189
162
  - spec/cases/realtime_updates_spec.rb
190
163
  - spec/cases/rest_api_spec.rb
191
164
  - spec/cases/test_users_spec.rb
192
165
  - spec/cases/uploadable_io_spec.rb
166
+ - spec/cases/utils_spec.rb
193
167
  - spec/fixtures/beach.jpg
168
+ - spec/fixtures/cat.m4v
194
169
  - spec/fixtures/facebook_data.yml
195
170
  - spec/fixtures/mock_facebook_responses.yml
196
171
  - spec/spec_helper.rb
197
172
  - spec/support/graph_api_shared_examples.rb
198
- - spec/support/live_testing_data_helper.rb
173
+ - spec/support/json_testing_fix.rb
174
+ - spec/support/koala_test.rb
199
175
  - spec/support/mock_http_service.rb
176
+ - spec/support/ordered_hash.rb
200
177
  - spec/support/rest_api_shared_examples.rb
201
- - spec/support/setup_mocks_or_live.rb
202
178
  - spec/support/uploadable_io_shared_examples.rb
@@ -1,146 +0,0 @@
1
- module Koala
2
- class Response
3
- attr_reader :status, :body, :headers
4
- def initialize(status, body, headers)
5
- @status = status
6
- @body = body
7
- @headers = headers
8
- end
9
- end
10
-
11
- module HTTPService
12
- # common functionality for all HTTP services
13
- def self.included(base)
14
- base.class_eval do
15
- class << self
16
- attr_accessor :always_use_ssl
17
- end
18
-
19
- def self.server(options = {})
20
- "#{options[:beta] ? "beta." : ""}#{options[:rest_api] ? Facebook::REST_SERVER : Facebook::GRAPH_SERVER}"
21
- end
22
-
23
- protected
24
-
25
- def self.params_require_multipart?(param_hash)
26
- param_hash.any? { |key, value| value.kind_of?(Koala::UploadableIO) }
27
- end
28
-
29
- def self.multipart_requires_content_type?
30
- true
31
- end
32
- end
33
- end
34
- end
35
-
36
- module NetHTTPService
37
- # this service uses Net::HTTP to send requests to the graph
38
- def self.included(base)
39
- base.class_eval do
40
- require "net/http" unless defined?(Net::HTTP)
41
- require "net/https"
42
- require "net/http/post/multipart"
43
-
44
- include Koala::HTTPService
45
-
46
- def self.make_request(path, args, verb, options = {})
47
- # We translate args to a valid query string. If post is specified,
48
- # we send a POST request to the given path with the given arguments.
49
-
50
- # by default, we use SSL only for private requests
51
- # this makes public requests faster
52
- private_request = args["access_token"] || @always_use_ssl || options[:use_ssl]
53
-
54
- # if the verb isn't get or post, send it as a post argument
55
- args.merge!({:method => verb}) && verb = "post" if verb != "get" && verb != "post"
56
-
57
- http = create_http(server(options), private_request, options)
58
- http.use_ssl = true if private_request
59
-
60
- result = http.start do |http|
61
- response, body = if verb == "post"
62
- if params_require_multipart? args
63
- http.request Net::HTTP::Post::Multipart.new path, encode_multipart_params(args)
64
- else
65
- http.post(path, encode_params(args))
66
- end
67
- else
68
- http.get("#{path}?#{encode_params(args)}")
69
- end
70
-
71
- Koala::Response.new(response.code.to_i, body, response)
72
- end
73
- end
74
-
75
- protected
76
- def self.encode_params(param_hash)
77
- # unfortunately, we can't use to_query because that's Rails, not Ruby
78
- # if no hash (e.g. no auth token) return empty string
79
- ((param_hash || {}).collect do |key_and_value|
80
- key_and_value[1] = key_and_value[1].to_json if key_and_value[1].class != String
81
- "#{key_and_value[0].to_s}=#{CGI.escape key_and_value[1]}"
82
- end).join("&")
83
- end
84
-
85
- def self.encode_multipart_params(param_hash)
86
- Hash[*param_hash.collect do |key, value|
87
- [key, value.kind_of?(Koala::UploadableIO) ? value.to_upload_io : value]
88
- end.flatten]
89
- end
90
-
91
- def self.create_http(server, private_request, options)
92
- if options[:proxy]
93
- proxy = URI.parse(options[:proxy])
94
- http = Net::HTTP.new(server, private_request ? 443 : nil,
95
- proxy.host, proxy.port, proxy.user, proxy.password)
96
- else
97
- http = Net::HTTP.new(server, private_request ? 443 : nil)
98
- end
99
- if options[:timeout]
100
- http.open_timeout = options[:timeout]
101
- http.read_timeout = options[:timeout]
102
- end
103
- http
104
- end
105
-
106
- end
107
- end
108
- end
109
-
110
- module TyphoeusService
111
- # this service uses Typhoeus to send requests to the graph
112
-
113
- def self.included(base)
114
- base.class_eval do
115
- require "typhoeus" unless defined?(Typhoeus)
116
- include Typhoeus
117
-
118
- include Koala::HTTPService
119
-
120
- def self.make_request(path, args, verb, options = {})
121
- # if the verb isn't get or post, send it as a post argument
122
- args.merge!({:method => verb}) && verb = "post" if verb != "get" && verb != "post"
123
-
124
- # switch any UploadableIOs to the files Typhoeus expects
125
- args.each_pair {|key, value| args[key] = value.to_file if value.is_a?(UploadableIO)}
126
-
127
- # you can pass arguments directly to Typhoeus using the :typhoeus_options key
128
- typhoeus_options = {:params => args}.merge(options[:typhoeus_options] || {})
129
-
130
- # by default, we use SSL only for private requests (e.g. with access token)
131
- # this makes public requests faster
132
- prefix = (args["access_token"] || @always_use_ssl || options[:use_ssl]) ? "https" : "http"
133
-
134
- response = self.send(verb, "#{prefix}://#{server(options)}#{path}", typhoeus_options)
135
- Koala::Response.new(response.code, response.body, response.headers_hash)
136
- end
137
-
138
- private
139
-
140
- def self.multipart_requires_content_type?
141
- false # Typhoeus handles multipart file types, we don't have to require it
142
- end
143
- end # class_eval
144
- end
145
- end
146
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- class Bear
5
- include Koala::HTTPService
6
- end
7
-
8
- describe "Koala::HTTPService" do
9
-
10
- describe "common methods" do
11
- describe "always_use_ssl accessor" do
12
- it "should be added" do
13
- # in Ruby 1.8, .methods returns strings
14
- # in Ruby 1.9, .method returns symbols
15
- Bear.methods.collect {|m| m.to_sym}.should include(:always_use_ssl)
16
- Bear.methods.collect {|m| m.to_sym}.should include(:always_use_ssl=)
17
- end
18
- end
19
-
20
- describe "server" do
21
- describe "without options[:beta]" do
22
- it "should return the rest server if options[:rest_api]" do
23
- Bear.server(:rest_api => true).should == Koala::Facebook::REST_SERVER
24
- end
25
-
26
- it "should return the rest server if !options[:rest_api]" do
27
- Bear.server(:rest_api => false).should == Koala::Facebook::GRAPH_SERVER
28
- Bear.server({}).should == Koala::Facebook::GRAPH_SERVER
29
- end
30
- end
31
-
32
- describe "without options[:beta]" do
33
- before :each do
34
- @options = {:beta => true}
35
- end
36
-
37
- it "should return the rest server if options[:rest_api]" do
38
- server = Bear.server(@options.merge(:rest_api => true))
39
- server.should =~ Regexp.new(Koala::Facebook::REST_SERVER)
40
- server.should =~ /beta\./
41
- end
42
-
43
- it "should return the rest server if !options[:rest_api]" do
44
- server = Bear.server(:beta => true)
45
- server.should =~ Regexp.new(Koala::Facebook::GRAPH_SERVER)
46
- server.should =~ /beta\./
47
- end
48
- end
49
-
50
- end
51
-
52
- end
53
-
54
- end