sharemotion 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +128 -0
- data/Rakefile +24 -0
- data/Sharemotion.gemspec +19 -0
- data/app/app_delegate.rb +15 -0
- data/app/test_view_controller.rb +111 -0
- data/lib/sharemotion/item.rb +20 -0
- data/lib/sharemotion/sharers/email/shmemail.rb +23 -0
- data/lib/sharemotion/sharers/email/shmemail_composer_view.rb +33 -0
- data/lib/sharemotion/sharers/facebook/shmfacebook.rb +35 -0
- data/lib/sharemotion/sharers/sharer.rb +15 -0
- data/lib/sharemotion/sharers/sms/shmsms.rb +23 -0
- data/lib/sharemotion/sharers/sms/shmsms_composer_view.rb +24 -0
- data/lib/sharemotion/sharers/twitter/shmtwitter.rb +21 -0
- data/lib/sharemotion/sharers/twitter/shmtwitter_composer_view.rb +26 -0
- data/lib/sharemotion/sheet.rb +30 -0
- data/lib/sharemotion/version.rb +3 -0
- data/lib/sharemotion.rb +8 -0
- data/resources/English.lproj/Localizable.strings +9 -0
- data/resources/French.lproj/Localizable.strings +2 -0
- data/spec/sharer_spec.rb +16 -0
- data/spec/sheet_spec.rb +24 -0
- data/spec/standalone_share_spec.rb +24 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Joffrey Jaffeux <j.jaffeux@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Sharemotion
|
2
|
+
|
3
|
+
|
4
|
+
## Overview
|
5
|
+
|
6
|
+
**Sharemotion**, is a lightweight gem for RubyMotion. It provides functions to share text, urls,… on social networks or messages. If you need a full featured library you should use ShareKit.
|
7
|
+
|
8
|
+
### Setup
|
9
|
+
|
10
|
+
**Loot at the rakefile and the demo app for fast example**
|
11
|
+
|
12
|
+
1. Add facebook plist informations (Rakefile)
|
13
|
+
|
14
|
+
````ruby
|
15
|
+
app.info_plist['CFBundleURLTypes'] = [{'CFBundleURLSchemes' => ['fbxxxxxxxxxxxxx']}]
|
16
|
+
app.info_plist['FacebookAppID'] = "xxxxxxxxxxxxx"
|
17
|
+
````
|
18
|
+
|
19
|
+
2. Add facebook sdk through pods (Rakefile)
|
20
|
+
|
21
|
+
````ruby
|
22
|
+
app.pods do
|
23
|
+
pod 'Facebook-iOS-SDK'
|
24
|
+
end
|
25
|
+
````
|
26
|
+
|
27
|
+
3. Add frameworks (Rakefile)
|
28
|
+
|
29
|
+
````ruby
|
30
|
+
app.frameworks += ['MessageUI', 'Twitter']
|
31
|
+
````
|
32
|
+
|
33
|
+
3. gem install sharemotion
|
34
|
+
|
35
|
+
4. require 'sharemotion' (Rakefile)
|
36
|
+
|
37
|
+
### Usage
|
38
|
+
#### Getting started
|
39
|
+
|
40
|
+
````ruby
|
41
|
+
# create the item you want to share
|
42
|
+
# the basic item can have :title, :url, image(string url), :text, you can override the hash for each sharers
|
43
|
+
# some sharers have specific fields and some won't use all the base fields, described later
|
44
|
+
|
45
|
+
@item = Sharemotion::Item.new({
|
46
|
+
:title => "Look at that bro!",
|
47
|
+
:url => "http://www.google.fr",
|
48
|
+
:image => "http://www.aujardin.ch/photos/tulipe1.jpg",
|
49
|
+
:text => "You should watch this site, it's incredible",
|
50
|
+
:sharers => {
|
51
|
+
:email => {
|
52
|
+
:to => ["cat@gmail.com", "j.jaffeux@gmail.com"],
|
53
|
+
:text => "Well you shouldn't..."
|
54
|
+
},
|
55
|
+
:facebook => {
|
56
|
+
:caption => "OHAI",
|
57
|
+
:title => "HEY HEY"
|
58
|
+
}
|
59
|
+
}
|
60
|
+
})
|
61
|
+
|
62
|
+
|
63
|
+
# define sharers you want to use
|
64
|
+
# you can override the title of the sharer with a block
|
65
|
+
facebook = Sharemotion::SHMFacebook.alloc.initWithItem(@item) {|sharer|
|
66
|
+
sharer.sharer_title = "Bookface"
|
67
|
+
}
|
68
|
+
|
69
|
+
sharers = [
|
70
|
+
Sharemotion::SHMEmail.alloc.initWithItem(@item),
|
71
|
+
Sharemotion::SHMSms.alloc.initWithItem(@item),
|
72
|
+
Sharemotion::SHMTwitter.alloc.initWithItem(@item),
|
73
|
+
facebook
|
74
|
+
]
|
75
|
+
|
76
|
+
# Init the UIActionSheet with your sharers and display it
|
77
|
+
@sheet = Sharemotion::Sheet.alloc.initWithSharers(sharers, controller:self)
|
78
|
+
@sheet.showInView(self.view)
|
79
|
+
|
80
|
+
# You can also use a sharer directly
|
81
|
+
facebook = Sharemotion::SHMFacebook.alloc.initWithItem(@item)
|
82
|
+
facebook.share(self)
|
83
|
+
````
|
84
|
+
|
85
|
+
#### Documentation on sharers
|
86
|
+
- SHMEmail will use :text(string), :title(string), :html(boolean), :cc(array), :bcc(array), :to(array)
|
87
|
+
|
88
|
+
|
89
|
+
- SHMFacebook will use :url(string), :image(string), :caption(string), :title(string), :text(string)
|
90
|
+
|
91
|
+
- SHMSms will use :text(string), to(array)
|
92
|
+
|
93
|
+
- SHMtwitter will use :text(string), :url(string)
|
94
|
+
|
95
|
+
|
96
|
+
As you can see email and sms accept :to, however, email wants… emails and sms wants phonenumbers so if you want to use both of them with right data you have to use the override hash explained before :
|
97
|
+
|
98
|
+
|
99
|
+
````ruby
|
100
|
+
@item = Sharemotion::Item.new({
|
101
|
+
:title => "Look at that bro!",
|
102
|
+
:url => "http://www.google.fr",
|
103
|
+
:image => "http://www.aujardin.ch/photos/tulipe1.jpg",
|
104
|
+
:text => "You should watch this site, it's incredible",
|
105
|
+
:sharers => {
|
106
|
+
:email => {
|
107
|
+
:to => ["cat@gmail.com", "j.jaffeux@gmail.com"],
|
108
|
+
},
|
109
|
+
:sms => {
|
110
|
+
:to => ["06XXXXXXXX", "07XXXXXXXX"]
|
111
|
+
}
|
112
|
+
}
|
113
|
+
})
|
114
|
+
````
|
115
|
+
|
116
|
+
### Todo
|
117
|
+
|
118
|
+
Better documentation
|
119
|
+
|
120
|
+
More tests
|
121
|
+
|
122
|
+
More sharers
|
123
|
+
|
124
|
+
Twitter < IOS 5.0
|
125
|
+
|
126
|
+
Do not require Facebook SDK if you don't use Facebook sharer
|
127
|
+
|
128
|
+
Same for frameworks
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.unshift("/Library/RubyMotion/lib")
|
2
|
+
require 'motion/project'
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "bundler/setup"
|
5
|
+
require 'motion-cocoapods'
|
6
|
+
|
7
|
+
$:.unshift("./lib/")
|
8
|
+
require './lib/sharemotion'
|
9
|
+
|
10
|
+
Motion::Project::App.setup do |app|
|
11
|
+
app.name = 'Sharemotion'
|
12
|
+
|
13
|
+
app.info_plist['CFBundleURLTypes'] = [{'CFBundleURLSchemes' => ['fbxxxxxxxxxxxxx']}]
|
14
|
+
app.info_plist['FacebookAppID'] = "xxxxxxxxxxxxx"
|
15
|
+
|
16
|
+
app.pods do
|
17
|
+
pod 'Facebook-iOS-SDK'
|
18
|
+
end
|
19
|
+
|
20
|
+
#workaround for a bug in cocoapods
|
21
|
+
app.libs += ['/usr/lib/libsqlite3.dylib']
|
22
|
+
|
23
|
+
app.frameworks += ['MessageUI', 'Twitter']
|
24
|
+
end
|
data/Sharemotion.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/sharemotion/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "sharemotion"
|
6
|
+
s.version = Sharemotion::VERSION
|
7
|
+
s.authors = ["Joffrey Jafeux"]
|
8
|
+
s.email = ["j.jaffeux@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/jjaffeux/Sharemotion"
|
10
|
+
s.summary = "Simple sharer for rubymotion"
|
11
|
+
s.description = "Simple sharer for rubymotion"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_dependency "bubble-wrap", ">= 1.1.3"
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
end
|
data/app/app_delegate.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class AppDelegate
|
2
|
+
|
3
|
+
attr_accessor :view_controller
|
4
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
5
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
6
|
+
@view_controller = TestViewController.alloc.init
|
7
|
+
@view_controller.view.backgroundColor = UIColor.grayColor
|
8
|
+
@window.rootViewController = @view_controller
|
9
|
+
@window.makeKeyAndVisible
|
10
|
+
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
class TestViewController < UIViewController
|
2
|
+
|
3
|
+
attr_accessor :sheet
|
4
|
+
|
5
|
+
def viewDidLoad
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def viewWillAppear(animated)
|
10
|
+
@item = Sharemotion::Item.new({
|
11
|
+
:title => "Look at that bro!",
|
12
|
+
:url => "http://www.google.fr",
|
13
|
+
:image => "http://www.aujardin.ch/photos/tulipe1.jpg",
|
14
|
+
:text => "You should watch this site, it's incredible",
|
15
|
+
:sharers => {
|
16
|
+
:email => {
|
17
|
+
:to => ["cat@gmail.com", "j.jaffeux@gmail.com"],
|
18
|
+
:text => "Well you shouldn't..."
|
19
|
+
},
|
20
|
+
:facebook => {
|
21
|
+
:caption => "OHAI",
|
22
|
+
:title => "HEY HEY"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
})
|
26
|
+
|
27
|
+
show_sheet_button
|
28
|
+
share_email_button
|
29
|
+
share_twitter_button
|
30
|
+
share_facebook_button
|
31
|
+
share_sms_button
|
32
|
+
end
|
33
|
+
|
34
|
+
def show_sheet_button
|
35
|
+
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
|
36
|
+
button.frame = [[15, 50], [290, 25]]
|
37
|
+
button.setTitle("Share", forState:UIControlStateNormal)
|
38
|
+
button.setTitleColor(UIColor.blackColor, forState:UIControlStateNormal)
|
39
|
+
self.view.addSubview(button)
|
40
|
+
|
41
|
+
|
42
|
+
button.whenTapped do
|
43
|
+
facebook = Sharemotion::SHMFacebook.alloc.initWithItem(@item) {|sharer|
|
44
|
+
sharer.sharer_title = "Bookface"
|
45
|
+
}
|
46
|
+
|
47
|
+
sharers = [
|
48
|
+
Sharemotion::SHMEmail.alloc.initWithItem(@item),
|
49
|
+
Sharemotion::SHMSms.alloc.initWithItem(@item),
|
50
|
+
Sharemotion::SHMTwitter.alloc.initWithItem(@item),
|
51
|
+
facebook
|
52
|
+
]
|
53
|
+
|
54
|
+
@sheet = Sharemotion::Sheet.alloc.initWithSharers(sharers, controller:self)
|
55
|
+
@sheet.showInView(self.view)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def share_email_button
|
60
|
+
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
|
61
|
+
button.frame = [[15, 100], [290, 25]]
|
62
|
+
button.setTitle("Share via mail", forState:UIControlStateNormal)
|
63
|
+
button.setTitleColor(UIColor.blackColor, forState:UIControlStateNormal)
|
64
|
+
self.view.addSubview(button)
|
65
|
+
|
66
|
+
button.whenTapped do
|
67
|
+
email = Sharemotion::SHMEmail.alloc.initWithItem(@item)
|
68
|
+
email.share(self)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def share_twitter_button
|
73
|
+
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
|
74
|
+
button.frame = [[15, 150], [290, 25]]
|
75
|
+
button.setTitle("Share via twitter", forState:UIControlStateNormal)
|
76
|
+
button.setTitleColor(UIColor.blackColor, forState:UIControlStateNormal)
|
77
|
+
self.view.addSubview(button)
|
78
|
+
|
79
|
+
button.whenTapped do
|
80
|
+
twitter = Sharemotion::SHMTwitter.alloc.initWithItem(@item)
|
81
|
+
twitter.share(self)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def share_facebook_button
|
86
|
+
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
|
87
|
+
button.frame = [[15, 200], [290, 25]]
|
88
|
+
button.setTitle("Share via facebook", forState:UIControlStateNormal)
|
89
|
+
button.setTitleColor(UIColor.blackColor, forState:UIControlStateNormal)
|
90
|
+
self.view.addSubview(button)
|
91
|
+
|
92
|
+
button.whenTapped do
|
93
|
+
facebook = Sharemotion::SHMFacebook.alloc.initWithItem(@item)
|
94
|
+
facebook.share(self)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def share_sms_button
|
99
|
+
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
|
100
|
+
button.frame = [[15, 250], [290, 25]]
|
101
|
+
button.setTitle("Share via sms", forState:UIControlStateNormal)
|
102
|
+
button.setTitleColor(UIColor.blackColor, forState:UIControlStateNormal)
|
103
|
+
self.view.addSubview(button)
|
104
|
+
|
105
|
+
button.whenTapped do
|
106
|
+
sms = Sharemotion::SHMSms.alloc.initWithItem(@item)
|
107
|
+
sms.share(self)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class Item
|
4
|
+
|
5
|
+
def initialize(item)
|
6
|
+
@item = item
|
7
|
+
end
|
8
|
+
|
9
|
+
def merge_keys_for_sharer(sharer)
|
10
|
+
if @item[:sharers] && @item[:sharers][:"#{sharer.to_s.downcase}"]
|
11
|
+
@item[:sharers][:"#{sharer.to_s.downcase}"].each do |key, value|
|
12
|
+
@item[key.to_sym] = value
|
13
|
+
end
|
14
|
+
@item.delete(:sharers)
|
15
|
+
end
|
16
|
+
@item
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class SHMEmail < Sharemotion::Sharer
|
4
|
+
|
5
|
+
def initWithItem(item, &block)
|
6
|
+
self.sharer_title = self.to_s
|
7
|
+
super(item, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"Email"
|
12
|
+
end
|
13
|
+
|
14
|
+
def share(controller)
|
15
|
+
if MFMailComposeViewController.canSendMail
|
16
|
+
email_composer_view = SHMEmailComposerView.alloc.initWithItem(@item, controller:controller)
|
17
|
+
email_composer_view.display
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class SHMEmailComposerView < MFMailComposeViewController
|
4
|
+
|
5
|
+
def initWithItem(item, controller:controller)
|
6
|
+
@item, @controller = item, controller
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def display
|
11
|
+
self.init
|
12
|
+
self.mailComposeDelegate = self
|
13
|
+
self.setSubject("#{@item[:title]}")
|
14
|
+
self.setMessageBody("#{@item[:text]}", isHTML:html)
|
15
|
+
self.setCcRecipients(@item[:cc])
|
16
|
+
self.setBccRecipients(@item[:bcc])
|
17
|
+
self.setToRecipients(@item[:to])
|
18
|
+
@controller.presentModalViewController(self, animated:true)
|
19
|
+
end
|
20
|
+
|
21
|
+
def mailComposeController(controller, didFinishWithResult:result, error:error)
|
22
|
+
controller.dismissModalViewControllerAnimated(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def html
|
28
|
+
@item[:html] || false
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class SHMFacebook < Sharemotion::Sharer
|
4
|
+
|
5
|
+
def initWithItem(item, &block)
|
6
|
+
self.sharer_title = self.to_s
|
7
|
+
super(item, &block)
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"SHMFacebook"
|
13
|
+
end
|
14
|
+
|
15
|
+
def share(controller)
|
16
|
+
@facebook = Facebook.alloc.initWithAppId(FBSession.activeSession.appID, andDelegate:nil)
|
17
|
+
@facebook.accessToken = FBSession.activeSession.accessToken
|
18
|
+
@facebook.expirationDate = FBSession.activeSession.expirationDate
|
19
|
+
|
20
|
+
params = {
|
21
|
+
:app_id => FBSession.activeSession.appID,
|
22
|
+
:link => "#{@item[:url]}",
|
23
|
+
:picture => "#{@item[:image]}",
|
24
|
+
:name => "#{@item[:title]}",
|
25
|
+
:caption => "#{@item[:caption]}",
|
26
|
+
:description => "#{@item[:text]}"
|
27
|
+
}
|
28
|
+
|
29
|
+
@facebook.dialog("feed", andParams:params, andDelegate:nil)
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class SHMSms < Sharemotion::Sharer
|
4
|
+
|
5
|
+
def initWithItem(item, &block)
|
6
|
+
self.sharer_title = self.to_s
|
7
|
+
super(item, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"Sms"
|
12
|
+
end
|
13
|
+
|
14
|
+
def share(controller)
|
15
|
+
if MFMessageComposeViewController.canSendText
|
16
|
+
sms_composer_view = SHMSmsComposerView.alloc.initWithItem(@item, controller:controller)
|
17
|
+
sms_composer_view.display
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class SHMSmsComposerView < MFMessageComposeViewController
|
4
|
+
|
5
|
+
def initWithItem(item, controller:controller)
|
6
|
+
@item, @controller = item, controller
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def display
|
11
|
+
self.init
|
12
|
+
self.messageComposeDelegate = self
|
13
|
+
self.body = "#{@item[:text]}"
|
14
|
+
self.recipients = "#{@item[:to]}"
|
15
|
+
@controller.presentModalViewController(self, animated:true)
|
16
|
+
end
|
17
|
+
|
18
|
+
def messageComposeViewController(controller, didFinishWithResult:result)
|
19
|
+
controller.dismissModalViewControllerAnimated(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class SHMTwitter < Sharemotion::Sharer
|
4
|
+
|
5
|
+
def initWithItem(item, &block)
|
6
|
+
self.sharer_title = self.to_s
|
7
|
+
super(item, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"Twitter"
|
12
|
+
end
|
13
|
+
|
14
|
+
def share(controller)
|
15
|
+
twitter_composer_view = SHMTwitterComposerView.alloc.initWithItem(@item, controller:controller)
|
16
|
+
twitter_composer_view.display
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class SHMTwitterComposerView < TWTweetComposeViewController
|
4
|
+
|
5
|
+
def initWithItem(item, controller:controller)
|
6
|
+
@item, @controller = item, controller
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def display
|
11
|
+
self.init
|
12
|
+
self.setInitialText("#{@item[:text]}")
|
13
|
+
self.addURL(NSURL.alloc.initWithString("#{@item[:url]}")) unless @item[:url].nil?
|
14
|
+
self.completionHandler = lambda{|result| handle_tweet_completion(result)}
|
15
|
+
@controller.presentModalViewController(self, animated:true)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def handle_tweet_completion(result)
|
21
|
+
self.dismissModalViewControllerAnimated(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Sharemotion
|
2
|
+
|
3
|
+
class Sheet < UIActionSheet
|
4
|
+
|
5
|
+
attr_writer :title
|
6
|
+
attr_reader :controller, :sharers
|
7
|
+
|
8
|
+
def initWithSharers(sharers, controller:controller, &block)
|
9
|
+
@sharers, @controller = sharers, controller
|
10
|
+
self.initWithTitle(nil, delegate:self, cancelButtonTitle:nil,
|
11
|
+
destructiveButtonTitle:nil, otherButtonTitles:nil)
|
12
|
+
self.sheet_configuration
|
13
|
+
yield(self) if block_given?
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def sheet_configuration
|
18
|
+
@sharers.each { |s| self.addButtonWithTitle(s.sharer_title) }
|
19
|
+
self.cancelButtonIndex = self.addButtonWithTitle(
|
20
|
+
BW.localized_string(:shm_cancel, 'Cancel'))
|
21
|
+
self.title = "Share"
|
22
|
+
end
|
23
|
+
|
24
|
+
def actionSheet(action_sheet, clickedButtonAtIndex:index)
|
25
|
+
@sharers[index].share(@controller) unless self.cancelButtonIndex == index
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/sharemotion.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'bubble-wrap/core'
|
2
|
+
require "sharemotion/version"
|
3
|
+
|
4
|
+
BW.require File.expand_path('../sharemotion/**/*.rb', __FILE__) do
|
5
|
+
['email', 'sms', 'twitter', 'facebook'].each {|file|
|
6
|
+
file("lib/sharemotion/sharers/#{file}/shm#{file}.rb").depends_on('lib/sharemotion/sharers/sharer.rb')
|
7
|
+
}
|
8
|
+
end
|
data/spec/sharer_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
describe "Sharemotion/Sharers/Sharer" do
|
2
|
+
tests TestViewController
|
3
|
+
|
4
|
+
before do
|
5
|
+
tap('Share')
|
6
|
+
@sheet = @controller.sheet
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
tap(@sheet.subviews.last)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "the sharer title should be overrided with a block" do
|
14
|
+
@sheet.buttonTitleAtIndex(3).should == "Bookface"
|
15
|
+
end
|
16
|
+
end
|
data/spec/sheet_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
describe "Sharemotion/Sheet" do
|
2
|
+
tests TestViewController
|
3
|
+
|
4
|
+
before do
|
5
|
+
tap('Share')
|
6
|
+
@sheet = @controller.sheet
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
tap(@sheet.subviews.last)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should pop open the action sheet when share button is tapped" do
|
14
|
+
@sheet.should != nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "the sheet should have 5 buttons in a specific order and correct title" do
|
18
|
+
@sheet.buttonTitleAtIndex(0).should == "Email"
|
19
|
+
@sheet.buttonTitleAtIndex(1).should == "Sms"
|
20
|
+
@sheet.buttonTitleAtIndex(2).should == "Twitter"
|
21
|
+
@sheet.buttonTitleAtIndex(3).should == "Bookface"
|
22
|
+
@sheet.buttonTitleAtIndex(4).should == "Cancel"
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe "Sharemotion/Sharers/Share" do
|
2
|
+
tests TestViewController
|
3
|
+
|
4
|
+
it "should open the email composer view" do
|
5
|
+
tap('Share via mail')
|
6
|
+
@controller.modalViewController.class.should == Sharemotion::SHMEmailComposerView
|
7
|
+
end
|
8
|
+
|
9
|
+
it "shouldn't open the sms composer view" do
|
10
|
+
tap('Share via sms')
|
11
|
+
@controller.modalViewController.should == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should open the facebook composer view" do
|
15
|
+
tap('Share via facebook')
|
16
|
+
views(FBDialog).length.should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should open the twitter composer view" do
|
20
|
+
tap('Share via twitter')
|
21
|
+
views(TWTweetSheetCardView).length.should == 1
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sharemotion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joffrey Jafeux
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bubble-wrap
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.3
|
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: 1.1.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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: Simple sharer for rubymotion
|
47
|
+
email:
|
48
|
+
- j.jaffeux@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- Sharemotion.gemspec
|
59
|
+
- app/app_delegate.rb
|
60
|
+
- app/test_view_controller.rb
|
61
|
+
- lib/sharemotion.rb
|
62
|
+
- lib/sharemotion/item.rb
|
63
|
+
- lib/sharemotion/sharers/email/shmemail.rb
|
64
|
+
- lib/sharemotion/sharers/email/shmemail_composer_view.rb
|
65
|
+
- lib/sharemotion/sharers/facebook/shmfacebook.rb
|
66
|
+
- lib/sharemotion/sharers/sharer.rb
|
67
|
+
- lib/sharemotion/sharers/sms/shmsms.rb
|
68
|
+
- lib/sharemotion/sharers/sms/shmsms_composer_view.rb
|
69
|
+
- lib/sharemotion/sharers/twitter/shmtwitter.rb
|
70
|
+
- lib/sharemotion/sharers/twitter/shmtwitter_composer_view.rb
|
71
|
+
- lib/sharemotion/sheet.rb
|
72
|
+
- lib/sharemotion/version.rb
|
73
|
+
- resources/English.lproj/Localizable.strings
|
74
|
+
- resources/French.lproj/Localizable.strings
|
75
|
+
- spec/sharer_spec.rb
|
76
|
+
- spec/sheet_spec.rb
|
77
|
+
- spec/standalone_share_spec.rb
|
78
|
+
homepage: https://github.com/jjaffeux/Sharemotion
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.24
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Simple sharer for rubymotion
|
102
|
+
test_files:
|
103
|
+
- spec/sharer_spec.rb
|
104
|
+
- spec/sheet_spec.rb
|
105
|
+
- spec/standalone_share_spec.rb
|