facebokr 0.0.2
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.
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +19 -0
- data/Rakefile +1 -0
- data/bin/facebokr +55 -0
- data/facebokr.gemspec +18 -0
- data/lib/facebokr/app.rb +49 -0
- data/lib/facebokr/shell.rb +55 -0
- data/lib/facebokr/version.rb +3 -0
- data/lib/facebokr.rb +5 -0
- metadata +63 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Vladimir Yarotsky
|
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
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Facebokr
|
2
|
+
|
3
|
+
A tiny utility to facilitate facebook app development & debugging with onboard shell mode.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install facebokr
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
See facebokr --help
|
12
|
+
|
13
|
+
## Contributing
|
14
|
+
|
15
|
+
1. Fork it
|
16
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
17
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
18
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
19
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/facebokr
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'facebokr/version'
|
5
|
+
require 'facebokr/app'
|
6
|
+
require 'facebokr/shell'
|
7
|
+
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
Signal.trap("SIGINT") do
|
11
|
+
puts "Terminating"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
options = {
|
16
|
+
:shell => true,
|
17
|
+
:app_id => ENV["APP_ID"],
|
18
|
+
:app_secret => ENV["APP_SECRET"]
|
19
|
+
}
|
20
|
+
|
21
|
+
OptionParser.new(ARGV) do |opts|
|
22
|
+
opts.banner = "Usage: taketo [destination] [options]"
|
23
|
+
opts.version = ::Facebokr::VERSION
|
24
|
+
|
25
|
+
opts.separator ""
|
26
|
+
opts.separator "Mandatory options:"
|
27
|
+
|
28
|
+
opts.on("-i", "--app-id ID", "Facebook app id") { |v| options[:app_id] = v }
|
29
|
+
opts.on("-s", "--app-secret SECRET", "Facebook app secret") { |v| options[:app_secret] = v }
|
30
|
+
|
31
|
+
opts.separator "Special options:"
|
32
|
+
|
33
|
+
opts.on("-c", "--command COMMAND", "Execute one-shot command") do |v|
|
34
|
+
options[:shell] = false
|
35
|
+
options[:command] = v
|
36
|
+
end
|
37
|
+
end.parse!
|
38
|
+
|
39
|
+
begin
|
40
|
+
raise "Facebook app id not provided!" if String(options[:app_id]).empty?
|
41
|
+
raise "Facebook app secret not provided!" if String(options[:app_secret]).empty?
|
42
|
+
|
43
|
+
app = Facebokr::App.new(options[:app_id], options[:app_secret])
|
44
|
+
|
45
|
+
if options[:shell]
|
46
|
+
Facebokr::Shell.new(app).run
|
47
|
+
elsif options[:command]
|
48
|
+
puts app.public_send(command)
|
49
|
+
end
|
50
|
+
rescue SystemExit
|
51
|
+
# Do nothing
|
52
|
+
rescue Exception => e
|
53
|
+
$stderr.puts "An error occured: #{e.message}"
|
54
|
+
exit 1
|
55
|
+
end
|
data/facebokr.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'facebokr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "facebokr"
|
8
|
+
gem.version = Facebokr::VERSION
|
9
|
+
gem.authors = ["Vladimir Yarotsky"]
|
10
|
+
gem.email = ["vladimir.yarotsky@gmail.com"]
|
11
|
+
gem.summary = %q{Facebook developer command-line tools}
|
12
|
+
gem.homepage = ""
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
end
|
data/lib/facebokr/app.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Facebokr
|
6
|
+
GRAPH_URI = "https://graph.facebook.com"
|
7
|
+
|
8
|
+
class App
|
9
|
+
#
|
10
|
+
# @param app_id [String] Facebook application id
|
11
|
+
# @param app_secret [String] Facebook application secret
|
12
|
+
#
|
13
|
+
def initialize(app_id, app_secret)
|
14
|
+
@app_id = app_id
|
15
|
+
@app_secret = app_secret
|
16
|
+
end
|
17
|
+
|
18
|
+
def access_token
|
19
|
+
@access_token ||= begin
|
20
|
+
uri = og_uri("oauth/access_token", :client_id => @app_id, :client_secret => @app_secret, :grant_type => "client_credentials")
|
21
|
+
response = open(uri).read
|
22
|
+
response.gsub(/^access_token=/, "")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Creates a test user for given Facebook application
|
27
|
+
#
|
28
|
+
# @param options [Hash] Facebook test user options
|
29
|
+
# @option installed [Boolean] Automatically install application for test user
|
30
|
+
# @option permissions [String] Comma-separated list of FB OG permissions
|
31
|
+
#
|
32
|
+
def create_test_user(options = {})
|
33
|
+
uri = og_uri(@app_id, "accounts/test-users", options.merge(:access_token => access_token))
|
34
|
+
response = JSON.parse(open(uri).read)
|
35
|
+
response["data"].first
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def og_uri(*path_elements)
|
41
|
+
params = path_elements.last.is_a?(Hash) ? path_elements.pop : {}
|
42
|
+
wrapped_path = path_elements.join("/").gsub(/(.*)/, "/\\1").squeeze("/").chop
|
43
|
+
query = params.map { |k, v| "#{k}=#{URI.escape v.to_s}" }.join("&")
|
44
|
+
URI.join(GRAPH_URI, wrapped_path).tap { |u| u.query = query unless String(query).empty? }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Facebokr
|
2
|
+
|
3
|
+
class Shell
|
4
|
+
class Sandbox < BasicObject
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def access_token
|
10
|
+
@app.access_token
|
11
|
+
end
|
12
|
+
alias_method :token, :access_token
|
13
|
+
|
14
|
+
def create_test_user(options = {})
|
15
|
+
@app.create_test_user(options)
|
16
|
+
end
|
17
|
+
alias_method :ctu, :create_test_user
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_accessor :app
|
21
|
+
|
22
|
+
def initialize(app)
|
23
|
+
@app = app
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
prompt
|
28
|
+
$stdin.each_line do |line|
|
29
|
+
$stdout.puts format Sandbox.new(app).instance_eval(line)
|
30
|
+
prompt
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def prompt
|
37
|
+
$stdout.print '-> '
|
38
|
+
end
|
39
|
+
|
40
|
+
def format(obj)
|
41
|
+
case obj
|
42
|
+
when String
|
43
|
+
obj
|
44
|
+
when Hash
|
45
|
+
obj.map { |data| "%-20s: %s" % data }.join("\n")
|
46
|
+
when Array
|
47
|
+
obj.map(&method(:format)).join("\n")
|
48
|
+
else
|
49
|
+
obj.inspect
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
data/lib/facebokr.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: facebokr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vladimir Yarotsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- vladimir.yarotsky@gmail.com
|
17
|
+
executables:
|
18
|
+
- facebokr
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/facebokr
|
28
|
+
- facebokr.gemspec
|
29
|
+
- lib/facebokr.rb
|
30
|
+
- lib/facebokr/app.rb
|
31
|
+
- lib/facebokr/shell.rb
|
32
|
+
- lib/facebokr/version.rb
|
33
|
+
homepage: ''
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
hash: 4400371526783365738
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
hash: 4400371526783365738
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.25
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Facebook developer command-line tools
|
63
|
+
test_files: []
|