facemock 0.0.2 → 0.0.3
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.
- metadata +4 -70
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -22
- data/.rspec +0 -2
- data/.travis.yml +0 -6
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -154
- data/Rakefile +0 -6
- data/db/.gitkeep +0 -0
- data/facemock.gemspec +0 -32
- data/lib/facemock/config/database.rb +0 -99
- data/lib/facemock/config.rb +0 -92
- data/lib/facemock/errors.rb +0 -6
- data/lib/facemock/fb_graph/application/test_users.rb +0 -36
- data/lib/facemock/fb_graph/application/user/right.rb +0 -14
- data/lib/facemock/fb_graph/application/user.rb +0 -68
- data/lib/facemock/fb_graph/application.rb +0 -44
- data/lib/facemock/fb_graph/errors.rb +0 -11
- data/lib/facemock/fb_graph/user.rb +0 -14
- data/lib/facemock/fb_graph.rb +0 -36
- data/lib/facemock/version.rb +0 -3
- data/lib/facemock.rb +0 -15
- data/spec/facemock/config/database_spec.rb +0 -220
- data/spec/facemock/config_spec.rb +0 -195
- data/spec/facemock/fb_graph/application/test_users_spec.rb +0 -159
- data/spec/facemock/fb_graph/application/user/right_spec.rb +0 -10
- data/spec/facemock/fb_graph/application/user_spec.rb +0 -131
- data/spec/facemock/fb_graph/application_spec.rb +0 -140
- data/spec/facemock/fb_graph/errors_spec.rb +0 -13
- data/spec/facemock/fb_graph/user_spec.rb +0 -39
- data/spec/facemock/fb_graph_spec.rb +0 -54
- data/spec/facemock_spec.rb +0 -72
- data/spec/spec_helper.rb +0 -15
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facemock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: activerecord
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 4.1.4
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 4.1.4
|
30
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: sqlite3
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,40 +162,7 @@ email:
|
|
178
162
|
executables: []
|
179
163
|
extensions: []
|
180
164
|
extra_rdoc_files: []
|
181
|
-
files:
|
182
|
-
- .coveralls.yml
|
183
|
-
- .gitignore
|
184
|
-
- .rspec
|
185
|
-
- .travis.yml
|
186
|
-
- Gemfile
|
187
|
-
- LICENSE.txt
|
188
|
-
- README.md
|
189
|
-
- Rakefile
|
190
|
-
- db/.gitkeep
|
191
|
-
- facemock.gemspec
|
192
|
-
- lib/facemock.rb
|
193
|
-
- lib/facemock/config.rb
|
194
|
-
- lib/facemock/config/database.rb
|
195
|
-
- lib/facemock/errors.rb
|
196
|
-
- lib/facemock/fb_graph.rb
|
197
|
-
- lib/facemock/fb_graph/application.rb
|
198
|
-
- lib/facemock/fb_graph/application/test_users.rb
|
199
|
-
- lib/facemock/fb_graph/application/user.rb
|
200
|
-
- lib/facemock/fb_graph/application/user/right.rb
|
201
|
-
- lib/facemock/fb_graph/errors.rb
|
202
|
-
- lib/facemock/fb_graph/user.rb
|
203
|
-
- lib/facemock/version.rb
|
204
|
-
- spec/facemock/config/database_spec.rb
|
205
|
-
- spec/facemock/config_spec.rb
|
206
|
-
- spec/facemock/fb_graph/application/test_users_spec.rb
|
207
|
-
- spec/facemock/fb_graph/application/user/right_spec.rb
|
208
|
-
- spec/facemock/fb_graph/application/user_spec.rb
|
209
|
-
- spec/facemock/fb_graph/application_spec.rb
|
210
|
-
- spec/facemock/fb_graph/errors_spec.rb
|
211
|
-
- spec/facemock/fb_graph/user_spec.rb
|
212
|
-
- spec/facemock/fb_graph_spec.rb
|
213
|
-
- spec/facemock_spec.rb
|
214
|
-
- spec/spec_helper.rb
|
165
|
+
files: []
|
215
166
|
homepage: https://github.com/ogawatti/facemock
|
216
167
|
licenses:
|
217
168
|
- MIT
|
@@ -225,33 +176,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
176
|
- - ! '>='
|
226
177
|
- !ruby/object:Gem::Version
|
227
178
|
version: '0'
|
228
|
-
segments:
|
229
|
-
- 0
|
230
|
-
hash: 1510434959302606046
|
231
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
180
|
none: false
|
233
181
|
requirements:
|
234
182
|
- - ! '>='
|
235
183
|
- !ruby/object:Gem::Version
|
236
184
|
version: '0'
|
237
|
-
segments:
|
238
|
-
- 0
|
239
|
-
hash: 1510434959302606046
|
240
185
|
requirements: []
|
241
186
|
rubyforge_project:
|
242
187
|
rubygems_version: 1.8.25
|
243
188
|
signing_key:
|
244
189
|
specification_version: 3
|
245
190
|
summary: This is facebook mock application for fb_graph.
|
246
|
-
test_files:
|
247
|
-
- spec/facemock/config/database_spec.rb
|
248
|
-
- spec/facemock/config_spec.rb
|
249
|
-
- spec/facemock/fb_graph/application/test_users_spec.rb
|
250
|
-
- spec/facemock/fb_graph/application/user/right_spec.rb
|
251
|
-
- spec/facemock/fb_graph/application/user_spec.rb
|
252
|
-
- spec/facemock/fb_graph/application_spec.rb
|
253
|
-
- spec/facemock/fb_graph/errors_spec.rb
|
254
|
-
- spec/facemock/fb_graph/user_spec.rb
|
255
|
-
- spec/facemock/fb_graph_spec.rb
|
256
|
-
- spec/facemock_spec.rb
|
257
|
-
- spec/spec_helper.rb
|
191
|
+
test_files: []
|
data/.coveralls.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
service_name: travis-ci
|
data/.gitignore
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
tmp/
|
19
|
-
db/*.sqlite3
|
20
|
-
vendor/bundle/
|
21
|
-
vendor/bundler/
|
22
|
-
log/*.log
|
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 ogawa
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
[](http://badge.fury.io/rb/facemock)
|
2
|
-
[](https://travis-ci.org/ogawatti/facemock)
|
3
|
-
[](https://coveralls.io/r/ogawatti/facemock?branch=master)
|
4
|
-
[<img src="https://gemnasium.com/ogawatti/facemock.png" />](https://gemnasium.com/ogawatti/facemock)
|
5
|
-
[](https://codeclimate.com/github/ogawatti/facemock)
|
6
|
-
|
7
|
-
# Facemock
|
8
|
-
|
9
|
-
Facemock is facebook mock application for FbGraph.
|
10
|
-
|
11
|
-
## Installation
|
12
|
-
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
gem 'facemock'
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install facemock
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
### Mock on/off
|
28
|
-
|
29
|
-
for all gem
|
30
|
-
|
31
|
-
require 'facemock'
|
32
|
-
|
33
|
-
FbGraph #=> FbGraph
|
34
|
-
Facemock.on
|
35
|
-
FbGraph #=> Facemock::FbGraph
|
36
|
-
Facemock.off
|
37
|
-
FbGraph #=> FbGraph
|
38
|
-
|
39
|
-
for specified gem
|
40
|
-
|
41
|
-
require 'facemock'
|
42
|
-
|
43
|
-
FbGraph #=> FbGraph
|
44
|
-
Facemock::FbGraph.on
|
45
|
-
FbGraph #=> Facemock::FbGraph
|
46
|
-
Facemock::FbGraph.off
|
47
|
-
FbGraph #=> FbGraph
|
48
|
-
|
49
|
-
### Test User
|
50
|
-
|
51
|
-
require 'facemock'
|
52
|
-
|
53
|
-
Facemock.on
|
54
|
-
facebook_app_id = "100000000000000"
|
55
|
-
facebook_app_secret = "facemock_app_secret"
|
56
|
-
app = FbGraph::Application.new(facebook_app_id, secret: facebook_app_secret)
|
57
|
-
|
58
|
-
|
59
|
-
## Create Test User
|
60
|
-
user = app.test_user!
|
61
|
-
user = app.test_user!( { name: "test user", permissions: "email, read_stream" } )
|
62
|
-
user.name #=> "test user"
|
63
|
-
user.permissions #=> [:email, :read_stream]
|
64
|
-
|
65
|
-
|
66
|
-
## Get Created Test User
|
67
|
-
app.test_users #=> [#<Facemock::FbGraph::Application::User id: ...>, ...]
|
68
|
-
app.test_users.size #=> 2
|
69
|
-
test_users.first #=> User that was created at the last
|
70
|
-
test_users.last #=> User that was created at the first
|
71
|
-
|
72
|
-
test_users = app.test_users({ limit: 1, after: 1 })
|
73
|
-
test_users.size = 1
|
74
|
-
test_users.first.id #=> [#<Facemock::FbGraph::Application::User id: ...>, ...]
|
75
|
-
|
76
|
-
|
77
|
-
# Delete Test User
|
78
|
-
app.test_users.size #=> 2
|
79
|
-
app.test_users.first.destroy
|
80
|
-
app.test_users.size #=> 1
|
81
|
-
app.test_users.first.destroy
|
82
|
-
app.test_users #=> []
|
83
|
-
|
84
|
-
### User
|
85
|
-
|
86
|
-
require 'facemock'
|
87
|
-
|
88
|
-
Facemock.on
|
89
|
-
facebook_app_id = "100000000000000"
|
90
|
-
facebook_app_secret = "facemock_app_secret"
|
91
|
-
app = FbGraph::Application.new(facebook_app_id, secret: facebook_app_secret)
|
92
|
-
user = app.test_user!({name: "face mock", permissions: "email, read_stream"})
|
93
|
-
access_token = user.access_token
|
94
|
-
|
95
|
-
# Get User by Access Token
|
96
|
-
user = FbGraph::User.me(access_token)
|
97
|
-
user.name #=> "face mock"
|
98
|
-
user.permissions #=> [:email, :read_stream]
|
99
|
-
|
100
|
-
# Delete permission
|
101
|
-
user.revoke!
|
102
|
-
user.permissions #=> []
|
103
|
-
|
104
|
-
# Delete User
|
105
|
-
user.destroy
|
106
|
-
FbGraph::User.me(access_token) #=> nil
|
107
|
-
|
108
|
-
### Register Test User by yaml file
|
109
|
-
|
110
|
-
require 'facemock'
|
111
|
-
|
112
|
-
Facemock::FbGraph.on
|
113
|
-
Facemock::Config.load_users("./test_users.yml")
|
114
|
-
|
115
|
-
yaml file see belo.
|
116
|
-
|
117
|
-
---
|
118
|
-
- :app_id: '000000000000001'
|
119
|
-
:app_secret: test_secret_one
|
120
|
-
:users:
|
121
|
-
- :identifier: 100000000000001
|
122
|
-
:name: test user one
|
123
|
-
:email: test_user_one@example.com
|
124
|
-
:password: testpass
|
125
|
-
- :identifier: '100000000000002'
|
126
|
-
:name: test user two
|
127
|
-
:email: test_user_two@example.com
|
128
|
-
:password: testpass
|
129
|
-
- :app_id: '000000000000002'
|
130
|
-
:app_secret: test_secret_two
|
131
|
-
:users:
|
132
|
-
- :identifier: 100000000000003
|
133
|
-
:name: test user three
|
134
|
-
:email: test_user_three@example.com
|
135
|
-
:password: testpass
|
136
|
-
|
137
|
-
### Exception
|
138
|
-
|
139
|
-
require 'facemock'
|
140
|
-
|
141
|
-
Facemock.on
|
142
|
-
begin
|
143
|
-
raise FbGraph::Errors::InvalidToken.new "test exception"
|
144
|
-
rescue => e
|
145
|
-
puts "#{e.class} : #{e.message}" #=> Facemock::FbGraph::Errors::InvalidToken : test exception
|
146
|
-
end
|
147
|
-
|
148
|
-
## Contributing
|
149
|
-
|
150
|
-
1. Fork it
|
151
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
152
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
153
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
154
|
-
5. Create new Pull Request
|
data/Rakefile
DELETED
data/db/.gitkeep
DELETED
File without changes
|
data/facemock.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'facemock/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "facemock"
|
8
|
-
spec.version = Facemock::VERSION
|
9
|
-
spec.authors = ["ogawatti"]
|
10
|
-
spec.email = ["ogawattim@gmail.com"]
|
11
|
-
spec.description = %q{This gem is used to mock the communication part of the facebook graph api.}
|
12
|
-
spec.summary = %q{This is facebook mock application for fb_graph.}
|
13
|
-
spec.homepage = "https://github.com/ogawatti/facemock"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency "activerecord", "~> 4.1.4"
|
22
|
-
spec.add_dependency "sqlite3"
|
23
|
-
spec.add_dependency "fb_graph"
|
24
|
-
spec.add_dependency "hashie"
|
25
|
-
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
-
spec.add_development_dependency "rake"
|
28
|
-
spec.add_development_dependency "rspec"
|
29
|
-
spec.add_development_dependency "simplecov"
|
30
|
-
spec.add_development_dependency "pry"
|
31
|
-
spec.add_development_dependency "coveralls"
|
32
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
|
3
|
-
module Facemock
|
4
|
-
module Config
|
5
|
-
class Database
|
6
|
-
ADAPTER = "sqlite3"
|
7
|
-
DB_DIRECTORY = File.expand_path("../../../../db", __FILE__)
|
8
|
-
DEFAULT_DB_NAME = "facemock"
|
9
|
-
TABLE_NAMES = [:applications, :users, :user_rights]
|
10
|
-
|
11
|
-
attr_reader :name
|
12
|
-
|
13
|
-
def initialize(name=nil)
|
14
|
-
@name = (name.nil? || name.empty?) ? DEFAULT_DB_NAME : name
|
15
|
-
connect
|
16
|
-
create_tables
|
17
|
-
end
|
18
|
-
|
19
|
-
def connect
|
20
|
-
ActiveRecord::Base.establish_connection(adapter: ADAPTER, database: filepath)
|
21
|
-
connection = ActiveRecord::Base.connection unless ActiveRecord::Base.connected?
|
22
|
-
ActiveRecord::Migration.verbose = false
|
23
|
-
@state = :connected
|
24
|
-
connection
|
25
|
-
end
|
26
|
-
|
27
|
-
def disconnect!
|
28
|
-
ActiveRecord::Base.connection.disconnect!
|
29
|
-
@state = :disconnected
|
30
|
-
end
|
31
|
-
|
32
|
-
def connected?
|
33
|
-
@state == :connected
|
34
|
-
end
|
35
|
-
|
36
|
-
def drop
|
37
|
-
disconnect!
|
38
|
-
File.delete(filepath) if File.exist?(filepath)
|
39
|
-
end
|
40
|
-
|
41
|
-
def clear
|
42
|
-
drop_tables
|
43
|
-
create_tables
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_tables
|
47
|
-
if !File.exist?(filepath) || ActiveRecord::Base.connection.tables.empty?
|
48
|
-
TABLE_NAMES.each do |table_name|
|
49
|
-
unless ActiveRecord::Base.connection.table_exists? table_name
|
50
|
-
self.send "create_#{table_name}_table"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def drop_tables
|
57
|
-
if File.exist?(filepath) && !ActiveRecord::Base.connection.tables.empty?
|
58
|
-
TABLE_NAMES.each do |table_name|
|
59
|
-
if ActiveRecord::Base.connection.table_exists? table_name
|
60
|
-
ActiveRecord::Migration.drop_table table_name
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def filepath
|
67
|
-
name ||= @name
|
68
|
-
File.join(DB_DIRECTORY, "#{@name}.#{ADAPTER}")
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def create_applications_table
|
74
|
-
ActiveRecord::Migration.create_table :applications do |t|
|
75
|
-
t.string :secret, :null => false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def create_users_table
|
80
|
-
ActiveRecord::Migration.create_table :users do |t|
|
81
|
-
t.string :name, :null => false
|
82
|
-
t.string :email, :null => false
|
83
|
-
t.string :password, :null => false
|
84
|
-
t.boolean :installed, :null => false
|
85
|
-
t.string :access_token, :null => false
|
86
|
-
t.integer :application_id
|
87
|
-
t.timestamp :created_at, :null => false
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def create_user_rights_table
|
92
|
-
ActiveRecord::Migration.create_table :user_rights do |t|
|
93
|
-
t.string :name, :null => false
|
94
|
-
t.integer :user_id, :null => false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
data/lib/facemock/config.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'hashie'
|
3
|
-
require 'facemock/errors'
|
4
|
-
require 'facemock/config/database'
|
5
|
-
require 'facemock/fb_graph/application'
|
6
|
-
|
7
|
-
module Facemock
|
8
|
-
module Config
|
9
|
-
extend self
|
10
|
-
|
11
|
-
def default_database
|
12
|
-
Database.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def database(name=nil)
|
16
|
-
if name.nil? || name.empty?
|
17
|
-
@db = default_database
|
18
|
-
else
|
19
|
-
@db.disconnect! if @db
|
20
|
-
@db = Database.new(name)
|
21
|
-
end
|
22
|
-
@db
|
23
|
-
end
|
24
|
-
|
25
|
-
def reset_database
|
26
|
-
@db = nil
|
27
|
-
end
|
28
|
-
|
29
|
-
def load_users(ymlfile)
|
30
|
-
load_data = YAML.load_file(ymlfile)
|
31
|
-
raise Facemock::Errors::IncorrectDataFormat.new "data is not Array" unless load_data.kind_of?(Array)
|
32
|
-
|
33
|
-
load_data.each do |app_data|
|
34
|
-
data = Hashie::Mash.new(app_data)
|
35
|
-
app_id = data.app_id
|
36
|
-
app_secret = data.app_secret
|
37
|
-
users = data.users
|
38
|
-
|
39
|
-
# Validate data format
|
40
|
-
raise Facemock::Errors::IncorrectDataFormat.new "app id is empty" unless validate_id(app_id)
|
41
|
-
raise Facemock::Errors::IncorrectDataFormat.new "app secret is empty" unless validate_secret(app_secret)
|
42
|
-
raise Facemock::Errors::IncorrectDataFormat.new "users format is incorrect" unless validate_users(users)
|
43
|
-
|
44
|
-
# Create application and user record
|
45
|
-
self.database if @db
|
46
|
-
app = Facemock::FbGraph::Application.new(app_id, secret: app_secret)
|
47
|
-
users.each do |options|
|
48
|
-
app.test_user!(options)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def validate_id(id)
|
56
|
-
case id
|
57
|
-
when String then !id.empty?
|
58
|
-
when Integer then id >= 0
|
59
|
-
else false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def validate_secret(app_secret)
|
64
|
-
case app_secret
|
65
|
-
when String then !app_secret.empty?
|
66
|
-
else false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def validate_users(users)
|
71
|
-
case users
|
72
|
-
when Array
|
73
|
-
return false if users.empty?
|
74
|
-
users.each {|user| return false unless validate_user(Hashie::Mash.new(user)) }
|
75
|
-
true
|
76
|
-
else false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def validate_user(user)
|
81
|
-
return false unless validate_id(user.identifier)
|
82
|
-
[:name, :password, :name].each do |key|
|
83
|
-
value = user.send(key)
|
84
|
-
case value
|
85
|
-
when String then return false if value.empty?
|
86
|
-
else return false
|
87
|
-
end
|
88
|
-
end
|
89
|
-
true
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/lib/facemock/errors.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'facemock/fb_graph/application/user'
|
2
|
-
|
3
|
-
module Facemock
|
4
|
-
module FbGraph
|
5
|
-
class Application < ActiveRecord::Base
|
6
|
-
class TestUsers < Array
|
7
|
-
DEFAULT_LIMIT = 50
|
8
|
-
DEFAULT_AFTER = 0
|
9
|
-
|
10
|
-
def initialize(application_id, options={})
|
11
|
-
@limit = limit = (options[:limit] && options[:limit] > 0) ? options[:limit] : DEFAULT_LIMIT
|
12
|
-
@after = after = (options[:after] && options[:after] > 0) ? options[:after] : DEFAULT_AFTER
|
13
|
-
@application_id = application_id
|
14
|
-
st = after
|
15
|
-
ed = after + limit - 1
|
16
|
-
users = User.where(application_id: application_id).sort_by{|u| u.created_at}
|
17
|
-
users = users.reverse[st..ed] || []
|
18
|
-
super(users)
|
19
|
-
end
|
20
|
-
|
21
|
-
def collection
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def next
|
26
|
-
options = { limit: @limit, after: @after + @limit }
|
27
|
-
TestUsers.new(@application_id, options)
|
28
|
-
end
|
29
|
-
|
30
|
-
def select
|
31
|
-
{ limit: DEFAULT_LIMIT, after: DEFAULT_AFTER }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
|
3
|
-
module Facemock
|
4
|
-
module FbGraph
|
5
|
-
class Application < ActiveRecord::Base
|
6
|
-
class User < ActiveRecord::Base
|
7
|
-
class Right < ActiveRecord::Base
|
8
|
-
self.table_name = "user_rights"
|
9
|
-
belongs_to :user
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'hashie'
|
3
|
-
require 'facemock/fb_graph/application/user/right'
|
4
|
-
|
5
|
-
module Facemock
|
6
|
-
module FbGraph
|
7
|
-
class Application < ActiveRecord::Base
|
8
|
-
class User < ActiveRecord::Base
|
9
|
-
self.table_name = "users"
|
10
|
-
alias_attribute :identifier, :id
|
11
|
-
has_many :rights, :dependent => :destroy
|
12
|
-
attr_reader :permissions
|
13
|
-
|
14
|
-
def initialize(options={})
|
15
|
-
opts = Hashie::Mash.new(options)
|
16
|
-
identifier = opts.identifier || ("10000" + (0..9).to_a.shuffle[0..10].join).to_i
|
17
|
-
name = opts.name || rand(36**10).to_s(36)
|
18
|
-
email = opts.email || name.gsub(" ", "_") + "@example.com"
|
19
|
-
password = opts.password || rand(36**10).to_s(36)
|
20
|
-
installed = opts.installed || false
|
21
|
-
access_token = opts.access_token || Digest::SHA512.hexdigest(identifier.to_s)
|
22
|
-
@permissions = []
|
23
|
-
|
24
|
-
super(
|
25
|
-
:name => name,
|
26
|
-
:email => email,
|
27
|
-
:password => password,
|
28
|
-
:installed => installed,
|
29
|
-
:access_token => access_token
|
30
|
-
)
|
31
|
-
self.id = identifier
|
32
|
-
if opts.permissions
|
33
|
-
build_rights(opts.permissions)
|
34
|
-
set_permissions
|
35
|
-
elsif opts.application_id
|
36
|
-
self.application_id = opts.application_id
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def fetch
|
41
|
-
User.find_by_id(self.id)
|
42
|
-
end
|
43
|
-
|
44
|
-
def revoke!
|
45
|
-
self.rights.each{|right| right.destroy}
|
46
|
-
@permissions = []
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def set_permissions
|
52
|
-
@permissions = self.rights.inject([]) do |simbols, right|
|
53
|
-
simbols << right.name.to_sym
|
54
|
-
end
|
55
|
-
@permissions.uniq!
|
56
|
-
end
|
57
|
-
|
58
|
-
def build_rights(permissions_string)
|
59
|
-
permissions_string.gsub(/\s/, "").split(",").uniq.each do |permission_name|
|
60
|
-
unless self.rights.find{|perm| perm.name == permission_name}
|
61
|
-
self.rights.build(name: permission_name)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|