under-os-sharing 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/README.md +49 -0
- data/lib/under-os-sharing.rb +19 -0
- data/lib/under_os/receivers/instagram.rb +79 -0
- data/lib/under_os/sharing/controller.rb +56 -0
- data/lib/under_os/sharing/interaction.rb +24 -0
- data/lib/under_os/sharing.rb +19 -0
- data/resources/instagram.png +0 -0
- data/resources/instagram@2x.png +0 -0
- data/under-os-image.gemspec +22 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2bfbbf1c3c215a9202881178c6f2dc83835b0060
|
4
|
+
data.tar.gz: 88a3c9c98b3b15ecb4ba667be6970fe7808efdfb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67e1bdc41bd353a35df927d2006aca33b108b720d9db606285c07082ee0f5c66e3f2b3ed118e2778474a6598b91b9a924f3849a92508a73d008c28d11ccbb68f
|
7
|
+
data.tar.gz: 94199765fd7b1708642dc5b55f0febdcfaa2782a9259da72d69bdb629b4cd71f8f32d359794594d3b5c38bc00ad831fdbb9b29f3de2c4047eb4b3223eda78b73
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# UnderOS::Sharing
|
2
|
+
|
3
|
+
A simple API to share your content between apps. Basically a wrapper over the `UIActivityViewController`
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add the `under-os-sharing` into your `Gemfile` then in your code you should be able to run the following
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
sharing = UOS::Sharing.new
|
11
|
+
sharing.share("Message", UIImage...)
|
12
|
+
```
|
13
|
+
|
14
|
+
By default this package will use all the matching services/apps that are currently registered against the iOS,
|
15
|
+
but you can limit the number of options by specifying the black list with the `:exclue` option
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
sharing = UOS::Sharing.new(:exclude => %w[facebook email])
|
19
|
+
```
|
20
|
+
|
21
|
+
Or you can specify the white list with the `:receivers` option
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
sharing = UOS::Sharing.new(:receivers => %w[twitter message])
|
25
|
+
```
|
26
|
+
|
27
|
+
## List of supported services
|
28
|
+
|
29
|
+
* `instagram`
|
30
|
+
* `facebook`
|
31
|
+
* `twitter`
|
32
|
+
* `flickr`
|
33
|
+
* `vimeo`
|
34
|
+
* `weibo` - ask apple
|
35
|
+
* `message` - open up in the iMessage
|
36
|
+
* `email`
|
37
|
+
* `print`
|
38
|
+
* `copy`
|
39
|
+
* `contact` - open in the contacts app
|
40
|
+
* `save` - save to the photo album (for images)
|
41
|
+
* `reading` - add to the reading list
|
42
|
+
* `airdrop` - share via the airdrop
|
43
|
+
|
44
|
+
|
45
|
+
## Copyright & License
|
46
|
+
|
47
|
+
All code in this repository released under the terms of the MIT license
|
48
|
+
|
49
|
+
Copyright (C) 2014 Nikolay Nemshilov
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# just a gem hook
|
2
|
+
|
3
|
+
Motion::Project::App.instance_eval do
|
4
|
+
alias :setup_before_under_os_sharing :setup
|
5
|
+
|
6
|
+
def setup(*args, &block)
|
7
|
+
config.setup_blocks << proc do |app|
|
8
|
+
Dir.glob(File.dirname(__FILE__) + '/**/*.rb').reverse.each do |file|
|
9
|
+
app.files.insert(0, file) if file != __FILE__
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
setup_before_under_os_sharing *args do |app|
|
14
|
+
app.resources_dirs << File.dirname(__FILE__) + "/../resources"
|
15
|
+
|
16
|
+
instance_exec app, &block
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module UnderOs
|
2
|
+
class Sharing
|
3
|
+
class Instagram < UIActivity
|
4
|
+
def activityType
|
5
|
+
"com.under-os.share.instagram"
|
6
|
+
end
|
7
|
+
|
8
|
+
def activityTitle
|
9
|
+
"Instagram"
|
10
|
+
end
|
11
|
+
|
12
|
+
def activityImage
|
13
|
+
UIImage.imageNamed("instagram.png")
|
14
|
+
end
|
15
|
+
|
16
|
+
def canPerformWithActivityItems(items)
|
17
|
+
instagram_installed? && items.each do |item|
|
18
|
+
if item_is_large_enough_image?(item)
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def prepareWithActivityItems(items)
|
27
|
+
items.each do |item|
|
28
|
+
@image_title = item if item.is_a?(String)
|
29
|
+
@image_url = save(item) if item.is_a?(UIImage)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def performActivity
|
34
|
+
return activityDidFinish(false) if ! @image_url
|
35
|
+
|
36
|
+
@image_title = {"InstagramCaption" => @image_title} if @image_title
|
37
|
+
|
38
|
+
@interaction = UnderOs::Sharing::Interaction.new("com.instagram.exclusivegram")
|
39
|
+
@interaction.open @image_url, @image_title do |result|
|
40
|
+
activityDidFinish result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def instagram_installed?
|
47
|
+
UIApplication.sharedApplication.canOpenURL(NSURL.URLWithString("instagram://app"))
|
48
|
+
end
|
49
|
+
|
50
|
+
def item_is_large_enough_image?(item)
|
51
|
+
item.is_a?(UIImage) && item.size.height >= 612 && item.size.width >= 612
|
52
|
+
end
|
53
|
+
|
54
|
+
def save(image)
|
55
|
+
image_data = UIImageJPEGRepresentation(scale(image), 1.0)
|
56
|
+
filename = NSTemporaryDirectory().stringByAppendingPathComponent("instagram.igo")
|
57
|
+
NSURL.fileURLWithPath(filename) if image_data.writeToFile(filename, atomically:true)
|
58
|
+
end
|
59
|
+
|
60
|
+
def scale(image)
|
61
|
+
size = UOS::Point.new(x: 640, y: 640)
|
62
|
+
ratio = size.x / image.size.width
|
63
|
+
new_size = CGSizeMake(size.x, image.size.height * ratio)
|
64
|
+
offset_x = (size.x - new_size.width)/2
|
65
|
+
offset_y = (size.y - new_size.height)/2
|
66
|
+
|
67
|
+
UIGraphicsBeginImageContext(CGSizeMake(size.x, size.y))
|
68
|
+
context = UIGraphicsGetCurrentContext()
|
69
|
+
CGContextSetFillColorWithColor(context, UIColor.whiteColor.CGColor)
|
70
|
+
CGContextFillRect(context, CGRectMake(0,0,size.x, size.y))
|
71
|
+
image.drawInRect(CGRectMake(offset_x,offset_y,new_size.width,new_size.height))
|
72
|
+
new_image = UIGraphicsGetImageFromCurrentImageContext()
|
73
|
+
UIGraphicsEndImageContext()
|
74
|
+
|
75
|
+
new_image
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module UnderOs
|
2
|
+
class Sharing
|
3
|
+
def controller_for(items)
|
4
|
+
UIActivityViewController.alloc.tap do |controller|
|
5
|
+
controller.initWithActivityItems(items, applicationActivities: custom_activities)
|
6
|
+
controller.excludedActivityTypes = excluded_activities
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def custom_activities
|
11
|
+
[].tap do |activities|
|
12
|
+
CUSTOM_RECEIVERS.each do |key, receiver|
|
13
|
+
activities << receiver.alloc.init if receivers_include(key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def excluded_activities
|
19
|
+
[].tap do |activities|
|
20
|
+
NATIVE_RECEIVERS.each do |key, receiver|
|
21
|
+
activities << receiver unless receivers_include(key)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def receivers_include(key)
|
27
|
+
if @options.has_key?(:receivers)
|
28
|
+
@options[:receivers].map(&:to_sym).incude?(key)
|
29
|
+
elsif @options.has_key?(:exclude)
|
30
|
+
! @options[:exclude].map(&:to_sym).include?(key)
|
31
|
+
else
|
32
|
+
true # fallback to inclusion
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
CUSTOM_RECEIVERS = {
|
37
|
+
instagram: UnderOs::Sharing::Instagram
|
38
|
+
}
|
39
|
+
|
40
|
+
NATIVE_RECEIVERS = {
|
41
|
+
facebook: UIActivityTypePostToFacebook,
|
42
|
+
twitter: UIActivityTypePostToTwitter,
|
43
|
+
flickr: UIActivityTypePostToFlickr,
|
44
|
+
vimeo: UIActivityTypePostToVimeo,
|
45
|
+
weibo: UIActivityTypePostToWeibo,
|
46
|
+
message: UIActivityTypeMessage,
|
47
|
+
email: UIActivityTypeMail,
|
48
|
+
print: UIActivityTypePrint,
|
49
|
+
copy: UIActivityTypeCopyToPasteboard,
|
50
|
+
contact: UIActivityTypeAssignToContact,
|
51
|
+
save: UIActivityTypeSaveToCameraRoll,
|
52
|
+
reading: UIActivityTypeAddToReadingList,
|
53
|
+
airdrop: UIActivityTypePostToTencentWeibo
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module UnderOs
|
2
|
+
class Sharing
|
3
|
+
class Interaction
|
4
|
+
def initialize(uti)
|
5
|
+
@uti = uti
|
6
|
+
end
|
7
|
+
|
8
|
+
def open(url, annotation=nil, &block)
|
9
|
+
@callback = block
|
10
|
+
@root_view = UnderOs::App.navigation._.visibleViewController.view
|
11
|
+
|
12
|
+
@controller = UIDocumentInteractionController.interactionControllerWithURL(url)
|
13
|
+
@controller.annotation = annotation if annotation
|
14
|
+
@controller.delegate = self
|
15
|
+
@controller.setUTI @uti
|
16
|
+
@controller.presentOpenInMenuFromRect @root_view.frame, inView: @root_view, animated: true
|
17
|
+
end
|
18
|
+
|
19
|
+
def documentInteractionController(controller, willBeginSendingToApplication: application)
|
20
|
+
@callback.call(true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module UnderOs
|
2
|
+
class Sharing
|
3
|
+
VERSION = '1.0.0'
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def share(*objects, &block)
|
10
|
+
controller = controller_for(items_from(objects))
|
11
|
+
UnderOs::App.navigation.current_page._
|
12
|
+
.presentViewController(controller, animated: true, completion: block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def items_from(objects)
|
16
|
+
objects
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/under_os/sharing', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "under-os-sharing"
|
6
|
+
gem.version = UnderOs::Sharing::VERSION
|
7
|
+
gem.homepage = "http://under-os.com"
|
8
|
+
gem.summary = "The interapps content sharing API for UnderOS"
|
9
|
+
gem.description = "The interapps content sharing API for UnderOS. FTW"
|
10
|
+
|
11
|
+
gem.authors = ["Nikolay Nemshilov"]
|
12
|
+
gem.email = ['nemshilov@gmail.com']
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'under-os', '~> 0'#, path: '../under-os'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake', '~> 0'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: under-os-sharing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikolay Nemshilov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: under-os
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: The interapps content sharing API for UnderOS. FTW
|
42
|
+
email:
|
43
|
+
- nemshilov@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- lib/under-os-sharing.rb
|
52
|
+
- lib/under_os/receivers/instagram.rb
|
53
|
+
- lib/under_os/sharing.rb
|
54
|
+
- lib/under_os/sharing/controller.rb
|
55
|
+
- lib/under_os/sharing/interaction.rb
|
56
|
+
- resources/instagram.png
|
57
|
+
- resources/instagram@2x.png
|
58
|
+
- under-os-image.gemspec
|
59
|
+
homepage: http://under-os.com
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: The interapps content sharing API for UnderOS
|
83
|
+
test_files: []
|