apps 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6567ec4200bd064433ef5002a6cab70a98760770d9a765355b963c952ece266a
4
- data.tar.gz: e77e4e67936e3c8ae9de44f3e1391e789333d79f34ed33c427952a4636c5f2ca
3
+ metadata.gz: 6b23f1e570ff2fe9154e677f4ac4400ed38b15688a04f96c6c3bacf03bf37a9c
4
+ data.tar.gz: 9d7e953d209b24a18072870377506615248edc3851d6db2994331d05b4bdcac4
5
5
  SHA512:
6
- metadata.gz: 604fe4bae4ef91ec735b7ab6a7eafed71e9655b4001c1211b94e090922f33258b43a5f374d09dfc180d9b65fc5757302cfb695d3d30354b02e0280fe5f0bb445
7
- data.tar.gz: 8e5b56db99e84c88eeb90998d8f8e4ad1d4f2525072b54990273b85005dc668ed5ea1e1612ea56a354871428e32055cb554c3b33f5a778a802392b2eb2e37ba8
6
+ metadata.gz: b03cced80ee3d26790c915a33fe2106a743194860c0a78ee4d634d7b8c2c920814aa1f8b0631c2b956fb3b142eaecc0dc0c0df1f1d708d740f8990867da3fb7b
7
+ data.tar.gz: 7065dbcc46c911e8f45cc597371c4f43926499aa060cc39968b2f996da111242647aedd867447c4b0c21e0ad9cad668060a9f7e121b8376a1fbad0e0744aea5c
data/.rubocop ADDED
@@ -0,0 +1,12 @@
1
+ --fail-fast
2
+ --cache=true
3
+ --debug
4
+ --extra-details
5
+ --color
6
+ --rails
7
+ --auto-correct
8
+ app
9
+ config
10
+ lib
11
+ spec
12
+ vendor
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-11-29 01:07:29 -0500 using RuboCop version 0.51.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 13
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
11
+ # URISchemes: http, https
12
+ AllCops:
13
+ TargetRubyVersion: 2.3.1
14
+
15
+ Metrics/LineLength:
16
+ Max: 120
17
+
18
+ Metrics/ClassLength:
19
+ Max: 150
20
+
21
+ Metrics/ModuleLength:
22
+ Max: 150
23
+
24
+ Metrics/MethodLength:
25
+ Max: 50
26
+
27
+ Documentation:
28
+ Enabled: false
29
+
30
+ # Offense count: 1
31
+ Style/Documentation:
32
+ Exclude:
33
+ - 'spec/**/*'
34
+ - 'test/**/*'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apps (0.1.0)
4
+ apps (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,6 +1,23 @@
1
1
  # Apps
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/apps`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This is a toolkit to easily integrate into platform marketplaces and extension points. These tools help with various integration points and common boilerplate needed to get going.
4
+
5
+ The Apps gem is currently under development, with the goal of facilitating the following:
6
+
7
+ * Google
8
+ * [Gmail Add-ons](https://developers.google.com/gmail/add-ons/)
9
+ * [Gmail Email Markup](https://developers.google.com/gmail/markup/)
10
+ * AMP Pages
11
+ * Microsoft Office 365
12
+ * [Outlook Add-ins](https://docs.microsoft.com/en-us/outlook/add-ins/)
13
+ * [Outlook Actionable Messages](https://docs.microsoft.com/en-us/outlook/actionable-messages/)
14
+ * Slack
15
+ * Bots
16
+ * Commands
17
+ * Heroku
18
+ * Addons Marketplace (SSO)
19
+ * Facebook
20
+ * Instant Articles
4
21
 
5
22
  ## Installation
6
23
 
@@ -20,7 +37,28 @@ Or install it yourself as:
20
37
 
21
38
  ## Usage
22
39
 
23
- TODO: Coming Soon
40
+ ### Gmail Email Markup
41
+
42
+ You can generate [schema.org](http://schema.org) markup for email in Gmail utilizing simple helper classes.
43
+
44
+ * Use the helper methods in `Apps::Adapters::Gmail::Markup` to easily define your markup
45
+ * Helper methods to generate an object model for you to "fill in":
46
+ * Confirm Action - `Apps::Adapters::Gmail::Markup#build_confirm_action`
47
+ * Save Action - `Apps::Adapters::Gmail::Markup#build_save_action`
48
+ * RSVP Action - `Apps::Adapters::Gmail::Markup#build_rsvp_action`
49
+ * View Action - `Apps::Adapters::Gmail::Markup#build_view_action`
50
+ * Track Action - `Apps::Adapters::Gmail::Markup#build_track_action`
51
+ * Helper methods to serialize your object model:
52
+ * `as_json` generates a `Hash` represenation of metadata
53
+ * `to_json` generates a JSON string representation of metadata
54
+ * `to_script` generates a "pretty" JSON enclosed by `script` tags specifying `JSON-LD` type
55
+ * NOTE: `to_script` is only available on "context" objects that represent the root of the markup needed for embedding in emails. This is the object returned by each of the helper methods above for each "Action"
56
+
57
+ #### TODO
58
+
59
+ * Basic handler endpoints for "Actions" to interact with need to be facilitated (e.g. for RSVP Action)
60
+ * Email Markup helpers for other Gmail-supported metadata need to be implemented
61
+ * Additional Gmail integrations need to be developed
24
62
 
25
63
  ## Development
26
64
 
@@ -30,12 +68,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
30
68
 
31
69
  ## Contributing
32
70
 
33
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apps. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joelvh/apps. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
72
 
35
73
  ## License
36
74
 
37
75
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
-
39
- ## Code of Conduct
40
-
41
- Everyone interacting in the Apps project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/apps/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,23 @@
1
+ require_relative 'base'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ class Action < Base
8
+
9
+ attr_accessor :handler_url
10
+
11
+ def as_json
12
+ prune super.merge(
13
+ "handler" => {
14
+ "@type" => "HttpActionHandler",
15
+ "url" => handler_url
16
+ }
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ class Base
8
+ def initialize(**attrs)
9
+ attrs.each { |attr, value| instance_variable_set(:"@#{attr}", value) }
10
+ end
11
+
12
+ def type
13
+ @type ||= self.class.name.split('::')[-1]
14
+ end
15
+
16
+ def as_json
17
+ { "@type" => type }
18
+ end
19
+
20
+ def to_json(pretty: false)
21
+ pretty ? JSON.pretty_generate(as_json) : JSON.dump(as_json)
22
+ end
23
+
24
+ protected
25
+
26
+ def prune(hash)
27
+ hash.reject { |_, value| value.nil? }
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'base'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ class BaseContext < Base
8
+ def as_json
9
+ { "@context" => "http://schema.org" }.merge(super)
10
+ end
11
+
12
+ def to_script
13
+ buffer = []
14
+ buffer << %{<script type="application/ld+json">}
15
+ buffer << to_json(pretty: true)
16
+ buffer << %{</script>}
17
+ buffer.join("\n")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'action'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ # See: https://developers.google.com/gmail/markup/reference/one-click-action
8
+ # See: https://developers.google.com/gmail/markup/reference/types/ConfirmAction
9
+ class ConfirmAction < Action
10
+
11
+ attr_accessor :name, :confirmed
12
+
13
+ def as_json
14
+ prune super.merge(
15
+ "name" => name,
16
+ "confirmed" => confirmed&.as_json # Thing
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'base_context'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ class EmailMessage < BaseContext
8
+
9
+ attr_reader :action
10
+ attr_accessor :description, :publisher
11
+
12
+ def as_json
13
+ prune super.merge(
14
+ "potentialAction" => action&.as_json,
15
+ "publisher" => publisher&.as_json # Organization
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'base_context'
2
+ require_relative 'rsvp_action'
3
+ require_relative 'place'
4
+
5
+ module Apps
6
+ module Adapters
7
+ module Gmail
8
+ module Markup
9
+ class Event < BaseContext
10
+
11
+ attr_accessor :name, :start_date, :end_date, :location
12
+
13
+ def as_json
14
+ prune super.merge(
15
+ "name" => name,
16
+ "startDate" => start_date,
17
+ "endDate" => end_date,
18
+ "location" => location&.as_json,
19
+ "potentialAction" => actions.map(&:as_json)
20
+ )
21
+ end
22
+
23
+ def actions
24
+ @actions ||= []
25
+ end
26
+
27
+ def build_location(**attrs)
28
+ self.location = Place.new(**attrs)
29
+ end
30
+
31
+ def build_rsvp_actions
32
+ actions.clear.concat(%w[Yes No Maybe].map { |response| RsvpAction.new(response: response) })
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ require_relative 'base_context'
2
+ require_relative 'postal_address'
3
+
4
+ module Apps
5
+ module Adapters
6
+ module Gmail
7
+ module Markup
8
+ class ParcelDelivery < BaseContext
9
+
10
+ attr_reader :action
11
+ attr_accessor :delivery_address, :expected_arrival_until, :carrier_name
12
+ attr_accessor :product_name, :order_number, :merchant_name
13
+ attr_accessor :tracking_url
14
+
15
+ def as_json
16
+ prune super.merge(
17
+ "deliveryAddress" => delivery_address&.as_json,
18
+ "expectedArrivalUntil" => expected_arrival_until,
19
+ "carrier" => {
20
+ "@type" => "Organization",
21
+ "name" => carrier_name
22
+ },
23
+ "itemShipped" => {
24
+ "@type" => "Product",
25
+ "name" => product_name
26
+ },
27
+ "partOfOrder" => {
28
+ "@type" => "Order",
29
+ "orderNumber" => order_number,
30
+ "merchant" => {
31
+ "@type" => "Organization",
32
+ "name" => merchant_name
33
+ }
34
+ },
35
+ "trackingUrl" => tracking_url,
36
+ "potentialAction" => action&.as_json
37
+ )
38
+ end
39
+
40
+ def build_delivery_address(**attrs)
41
+ self.delivery_address = PostalAddress.new(**attrs)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'base'
2
+ require_relative 'postal_address'
3
+
4
+ module Apps
5
+ module Adapters
6
+ module Gmail
7
+ module Markup
8
+ class Place < Base
9
+
10
+ attr_accessor :name, :same_as, :address
11
+
12
+ def as_json
13
+ prune super.merge(
14
+ "sameAs" => same_as,
15
+ "name" => name,
16
+ "address" => address&.as_json
17
+ )
18
+ end
19
+
20
+ def build_address(**attrs)
21
+ self.address = PostalAddress.new(**attrs)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'base'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ class PostalAddress < Base
8
+
9
+ attr_accessor :name, :street, :locality, :region, :po_box, :postal_code, :country
10
+
11
+ def as_json
12
+ prune super.merge(
13
+ "name" => name,
14
+ "streetAddress" => street, # street address
15
+ "addressLocality" => locality, # city
16
+ "addressRegion" => region, # state (abbr)
17
+ "postOfficeBoxNumber" => po_box,
18
+ "postalCode" => postal_code, # zip code
19
+ "addressCountry" => country
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'action'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ # See: https://developers.google.com/gmail/markup/reference/rsvp-action
8
+ class RsvpAction < Action
9
+
10
+ attr_accessor :response, :additional_number_of_guests, :bringing_kids, :bringing_other_people
11
+
12
+ def as_json
13
+ prune super.merge(
14
+ "rsvpResponse" => response.downcase,
15
+ "additionalNumberOfGuests" => additional_number_of_guests&.to_i,
16
+ "bringingKids" => bringing_kids&.to_i,
17
+ "bringingOtherPeople" => bringing_other_people&.to_i,
18
+ # "comment" => {},
19
+ # "event" => {},
20
+ "attendance" => "http://schema.org/RsvpAttendance/#{response.capitalize}"
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'action'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ # See: https://developers.google.com/gmail/markup/reference/one-click-action
8
+ # See: https://developers.google.com/gmail/markup/reference/types/SaveAction
9
+ class SaveAction < Action
10
+
11
+ attr_accessor :name
12
+
13
+ def as_json
14
+ prune super.merge(
15
+ "name" => name
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'base'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ # See: https://developers.google.com/gmail/markup/reference/go-to-action
8
+ # See: https://developers.google.com/gmail/markup/reference/types/TrackAction
9
+ class TrackAction < Base
10
+
11
+ attr_accessor :name, :target, :delivery_method
12
+
13
+ def as_json
14
+ prune super.merge(
15
+ "name" => name,
16
+ "target" => target,
17
+ "deliveryMethod" => delivery_method&.as_json # DeliveryMethod
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'base'
2
+
3
+ module Apps
4
+ module Adapters
5
+ module Gmail
6
+ module Markup
7
+ # See: https://developers.google.com/gmail/markup/reference/go-to-action
8
+ # See: https://developers.google.com/gmail/markup/reference/types/ViewAction
9
+ class ViewAction < Base
10
+
11
+ attr_accessor :name, :target, :viewed
12
+
13
+ def as_json
14
+ prune super.merge(
15
+ "name" => name,
16
+ "target" => target,
17
+ "viewed" => viewed&.as_json # Thing
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'markup/event'
2
+ require_relative 'markup/email_message'
3
+ require_relative 'markup/parcel_delivery'
4
+ require_relative 'markup/confirm_action'
5
+ require_relative 'markup/save_action'
6
+ require_relative 'markup/view_action'
7
+ require_relative 'markup/track_action'
8
+
9
+ module Apps
10
+ module Adapters
11
+ module Gmail
12
+ module Markup
13
+ class << self
14
+ def build_confirm_action(description: nil, **attrs)
15
+ EmailMessage.new(description: description, action: ConfirmAction.new(**attrs))
16
+ end
17
+
18
+ def build_save_action(description: nil, **attrs)
19
+ EmailMessage.new(description: description, action: SaveAction.new(**attrs))
20
+ end
21
+
22
+ def build_rsvp_action(**attrs)
23
+ Event.new(**attrs).tap do |event|
24
+ event.build_location unless event.location
25
+ event.location.build_address unless event.location.address
26
+ event.build_rsvp_actions unless event.actions.any?
27
+ end
28
+ end
29
+
30
+ def build_view_action(target: nil, **attrs)
31
+ EmailMessage.new(action: ViewAction.new(target: target), **attrs)
32
+ end
33
+
34
+ def build_track_action(target: nil, **attrs)
35
+ ParcelDelivery.new(action: TrackAction.new(target: target), **attrs).tap do |email|
36
+ email.build_delivery_address unless email.delivery_address
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
data/lib/apps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apps
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Van Horn
@@ -62,6 +62,8 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
64
  - ".rspec"
65
+ - ".rubocop"
66
+ - ".rubocop.yml"
65
67
  - ".travis.yml"
66
68
  - Gemfile
67
69
  - Gemfile.lock
@@ -73,6 +75,20 @@ files:
73
75
  - bin/setup
74
76
  - exe/apps
75
77
  - lib/apps.rb
78
+ - lib/apps/adapters/gmail/markup.rb
79
+ - lib/apps/adapters/gmail/markup/action.rb
80
+ - lib/apps/adapters/gmail/markup/base.rb
81
+ - lib/apps/adapters/gmail/markup/base_context.rb
82
+ - lib/apps/adapters/gmail/markup/confirm_action.rb
83
+ - lib/apps/adapters/gmail/markup/email_message.rb
84
+ - lib/apps/adapters/gmail/markup/event.rb
85
+ - lib/apps/adapters/gmail/markup/parcel_delivery.rb
86
+ - lib/apps/adapters/gmail/markup/place.rb
87
+ - lib/apps/adapters/gmail/markup/postal_address.rb
88
+ - lib/apps/adapters/gmail/markup/rsvp_action.rb
89
+ - lib/apps/adapters/gmail/markup/save_action.rb
90
+ - lib/apps/adapters/gmail/markup/track_action.rb
91
+ - lib/apps/adapters/gmail/markup/view_action.rb
76
92
  - lib/apps/version.rb
77
93
  homepage: https://github.com/joelvh/apps
78
94
  licenses: