ajar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +33 -0
  5. data/Rakefile +1 -0
  6. data/ajar.gemspec +18 -0
  7. data/lib/ajar.rb +41 -0
  8. metadata +85 -0
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Pat Allan
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.
@@ -0,0 +1,33 @@
1
+ # Ajar
2
+
3
+ Allow Facebook access to your local pages when creating Open Graph objects and actions via the Ajar API.
4
+
5
+ ## Usage
6
+
7
+ Add the gem to your application's Gemfile:
8
+
9
+ gem 'ajar', '0.1.0'
10
+
11
+ Wrap your Koala graph in an Ajar instance with your developer key from http://ajar-web.herokuapp.com, and use `put_connections` to create a new open graph object.
12
+
13
+ graph = Ajar.new Koala::Facebook::API.new(token), 'my-token'
14
+ graph.put_connections 'me', 'namespace:action', :object => object_uri
15
+
16
+ When you're operating in a local Rails environment (development or test), Ajar will copy the HTML from the given URI to a public address which Facebook can access. When anyone other than Facebook accesses it, it'll redirect back to the original URI.
17
+
18
+ The generated public URIs for Facebook use both your developer key and a per-graph-object unique key - so they're not easy to guess. Also: don't go sharing your developer key unnecessarily. All that said - if you're happy with Facebook accessing your page, you shouldn't be too concerned about the page being available to the general public anyway.
19
+
20
+ ## Upcoming changes
21
+
22
+ * Proper domain for the site.
23
+ * Ability to customise which environments are considered 'local'.
24
+ * Developer key managed on a global level, instead of per instance.
25
+ * Tests.
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.name = 'ajar'
4
+ gem.version = '0.1.0'
5
+ gem.authors = ['Pat Allan']
6
+ gem.email = ['pat@freelancing-gods.com']
7
+ gem.summary = 'Redirect Facebook to Ajar versions of local pages.'
8
+ gem.description = "Uses Ajar's API to insert public URIs in place of local APIs for Facebook Open Graph connections."
9
+ gem.homepage = 'https://github.com/pat/ajar'
10
+
11
+ gem.files = `git ls-files`.split($/)
12
+ gem.executables = []
13
+ gem.test_files = []
14
+ gem.require_paths = ['lib']
15
+
16
+ gem.add_runtime_dependency 'httparty', '>= 0'
17
+ gem.add_runtime_dependency 'koala', '>= 0'
18
+ end
@@ -0,0 +1,41 @@
1
+ require 'open-uri'
2
+ require 'httparty'
3
+
4
+ class Ajar
5
+ SERVER = 'http://ajar-web.herokuapp.com'
6
+ HEADERS = {'Content-Type' => 'application/json'}
7
+
8
+ def initialize(graph, developer_key)
9
+ @graph, @developer_key = graph, developer_key
10
+ end
11
+
12
+ def put_connections(*arguments)
13
+ options = arguments.pop
14
+ options.keys.each do |key|
15
+ options[key] = external_uri_for options[key]
16
+ end if local_environment?
17
+
18
+ graph.put_connections *(arguments + [options])
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :graph, :developer_key
24
+
25
+ def external_uri_for(internal_uri)
26
+ HTTParty.post("#{SERVER}/api/pages.json",
27
+ :body => {
28
+ :page => {
29
+ :internal_uri => internal_uri,
30
+ :content => open(internal_uri).read
31
+ },
32
+ :key => developer_key
33
+ }.to_json,
34
+ :headers => HEADERS
35
+ )['url']
36
+ end
37
+
38
+ def local_environment?
39
+ Rails.env.development? || Rails.env.test?
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ajar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pat Allan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: koala
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Uses Ajar's API to insert public URIs in place of local APIs for Facebook
47
+ Open Graph connections.
48
+ email:
49
+ - pat@freelancing-gods.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - ajar.gemspec
60
+ - lib/ajar.rb
61
+ homepage: https://github.com/pat/ajar
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.23
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Redirect Facebook to Ajar versions of local pages.
85
+ test_files: []