facebokr 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9794cf3dcdec32b35feb0b591856ec080d869ecb
4
+ data.tar.gz: ce6b02022c96cf84112cadada4da69a098a73d19
5
+ SHA512:
6
+ metadata.gz: 02f511dc8342e837e0e3bee1f51215bbcffec3a5270c8a9c12bef8203ca0f58e4bc6f3dcb58f98561cbc0f12cba7403f831966d5b6d419c93893788baba03914
7
+ data.tar.gz: 8de1e2ace0d5acd9b4ad43cf9f79289accc533d7618833974b3270a11efc028c4c5db590466b39dab23d9312732aac4bde98b5f77f67b246320f6813befff8e7
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-2.0.0-p0@main
@@ -4,37 +4,55 @@ require 'rubygems'
4
4
  require 'facebokr/version'
5
5
  require 'facebokr/app'
6
6
  require 'facebokr/shell'
7
+ require 'yaml'
7
8
 
8
9
  require 'optparse'
9
10
 
10
- Signal.trap("SIGINT") do
11
- puts "Terminating"
12
- exit 1
11
+ Signal.trap("SIGINT") { exit }
12
+
13
+ DEFAULT_CONFIG = File.expand_path("~/.facebokr.yml")
14
+
15
+ def default_options
16
+ {
17
+ :shell => true,
18
+ :app_id => ENV["APP_ID"],
19
+ :app_secret => ENV["APP_SECRET"]
20
+ }
21
+ end
22
+
23
+ def options_from_config(config = DEFAULT_CONFIG)
24
+ if File.exists?(config)
25
+ Hash[YAML.load(File.read(config)).map { |k, v| [k.to_sym, v] }]
26
+ else
27
+ {}
28
+ end
13
29
  end
14
30
 
15
- options = {
16
- :shell => true,
17
- :app_id => ENV["APP_ID"],
18
- :app_secret => ENV["APP_SECRET"]
19
- }
31
+ def options_from_cli
32
+ options = {}
20
33
 
21
- OptionParser.new(ARGV) do |opts|
22
- opts.banner = "Usage: taketo [destination] [options]"
23
- opts.version = ::Facebokr::VERSION
34
+ OptionParser.new(ARGV) do |opts|
35
+ opts.banner = "Usage: taketo [destination] [options]"
36
+ opts.version = ::Facebokr::VERSION
24
37
 
25
- opts.separator ""
26
- opts.separator "Mandatory options:"
38
+ opts.separator ""
39
+ opts.separator "Mandatory options:"
27
40
 
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 }
41
+ opts.on("-i", "--app-id ID", "Facebook app id") { |v| options[:app_id] = v }
42
+ opts.on("-s", "--app-secret SECRET", "Facebook app secret") { |v| options[:app_secret] = v }
30
43
 
31
- opts.separator "Special options:"
44
+ opts.separator "Special options:"
32
45
 
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!
46
+ opts.on("-c", "--command COMMAND", "Execute one-shot command") do |v|
47
+ options[:shell] = false
48
+ options[:command] = v
49
+ end
50
+ end.parse!
51
+
52
+ options
53
+ end
54
+
55
+ options = default_options.merge(options_from_config).merge(options_from_cli)
38
56
 
39
57
  begin
40
58
  raise "Facebook app id not provided!" if String(options[:app_id]).empty?
@@ -35,6 +35,36 @@ module Facebokr
35
35
  response["data"].first
36
36
  end
37
37
 
38
+ # Creates an app request from given Facebook application
39
+ #
40
+ # @param fb_user_id [String] Facebook user id
41
+ # @param message [String] Request message text
42
+ # @param data [String] Optional request data
43
+ #
44
+ def create_app_request(fb_user_id, message, data = "")
45
+ require 'net/http'
46
+ uri = og_uri(fb_user_id, "apprequests")
47
+ response = JSON.parse(Net::HTTP.post_form(uri,
48
+ :access_token => access_token,
49
+ :message => message,
50
+ :data => data).body)
51
+ end
52
+
53
+ # Creates an app notification from given Facebook application
54
+ #
55
+ # @param fb_user_id [String] Facebook user id
56
+ # @param template [String] Notification message template
57
+ # @param href [String] optional href (relative path) to redirect user to
58
+ #
59
+ def create_app_notification(fb_user_id, template, href = "")
60
+ require 'net/http'
61
+ uri = og_uri(fb_user_id, "notifications")
62
+ response = JSON.parse(Net::HTTP.post_form(uri,
63
+ :access_token => access_token,
64
+ :template => template,
65
+ :href => href).body)
66
+ end
67
+
38
68
  private
39
69
 
40
70
  def og_uri(*path_elements)
@@ -1,3 +1,5 @@
1
+ require 'readline'
2
+
1
3
  module Facebokr
2
4
 
3
5
  class Shell
@@ -11,10 +13,20 @@ module Facebokr
11
13
  end
12
14
  alias_method :token, :access_token
13
15
 
14
- def create_test_user(options = {})
16
+ def test_user(options = {})
15
17
  @app.create_test_user(options)
16
18
  end
17
- alias_method :ctu, :create_test_user
19
+ alias_method :tu, :test_user
20
+
21
+ def app_request(*args)
22
+ @app.create_app_request(*args)
23
+ end
24
+ alias_method :ar, :app_request
25
+
26
+ def app_notification(*args)
27
+ @app.create_app_notification(*args)
28
+ end
29
+ alias_method :an, :app_notification
18
30
  end
19
31
 
20
32
  attr_accessor :app
@@ -24,17 +36,15 @@ module Facebokr
24
36
  end
25
37
 
26
38
  def run
27
- prompt
28
- $stdin.each_line do |line|
29
- $stdout.puts format Sandbox.new(app).instance_eval(line)
30
- prompt
39
+ while buf = Readline.readline(prompt, true) do
40
+ puts format Sandbox.new(app).instance_eval(buf)
31
41
  end
32
42
  end
33
43
 
34
44
  private
35
45
 
36
46
  def prompt
37
- $stdout.print '-> '
47
+ '-> '
38
48
  end
39
49
 
40
50
  def format(obj)
@@ -1,3 +1,3 @@
1
1
  module Facebokr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebokr
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.2
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vladimir Yarotsky
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-17 00:00:00.000000000 Z
11
+ date: 2013-04-22 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description:
15
14
  email:
@@ -20,6 +19,7 @@ extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
21
  - .gitignore
22
+ - .rvmrc
23
23
  - Gemfile
24
24
  - LICENSE.txt
25
25
  - README.md
@@ -32,32 +32,25 @@ files:
32
32
  - lib/facebokr/version.rb
33
33
  homepage: ''
34
34
  licenses: []
35
+ metadata: {}
35
36
  post_install_message:
36
37
  rdoc_options: []
37
38
  require_paths:
38
39
  - lib
39
40
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
41
  requirements:
42
- - - ! '>='
42
+ - - '>='
43
43
  - !ruby/object:Gem::Version
44
- segments:
45
- - 0
46
- hash: 4400371526783365738
47
44
  version: '0'
48
45
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
46
  requirements:
51
- - - ! '>='
47
+ - - '>='
52
48
  - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- hash: 4400371526783365738
56
49
  version: '0'
57
50
  requirements: []
58
51
  rubyforge_project:
59
- rubygems_version: 1.8.25
52
+ rubygems_version: 2.0.3
60
53
  signing_key:
61
- specification_version: 3
54
+ specification_version: 4
62
55
  summary: Facebook developer command-line tools
63
56
  test_files: []