kodeco 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21e401351ab9adc6500a6f950ae55044bb443ca6de317ca57acf8bc25f89bbbd
4
- data.tar.gz: b5ba461481bfa7a3023027cf780d0a58f1e570013364e433bbf3ffbf9fba7cad
3
+ metadata.gz: e2c3bf5ae4351b9f93929c33d3373a6b0c197a4a555f69d63191a327d5773e57
4
+ data.tar.gz: 1c07c086b622a92abc1c8b55013a64e3f2d6f8c725f59f396487b35db09986cd
5
5
  SHA512:
6
- metadata.gz: e2f70ef215eec74514d602c5d4de7fb1ef8f8fa15a7bbbafc5243b38ad07a7abeb4fecd7752885068e84776d850551a6b89876d7878405be05432e96443f657f
7
- data.tar.gz: a6439d86cf76759ea24c873f9eb2c09a0c3b18a7ed38cba3035b2066f532734556eacc36946bf7b97f48cd51d73b9a37cfaf5f02114d60d13871f1da255ba93a
6
+ metadata.gz: 1297bbbb47629bdf96ee0bcd6a8e658f5c2f1ac07e2ca4cda8842347ef348011cf34e4aabf22cb73c43cf9c1777debe211542324787e16918123b80dce99ad9e
7
+ data.tar.gz: 5678009ccbe2d9a3641376b20c59a9085b7140b086dcd265160727a5df605dc9a415401f32212c3c42b0f52992abfdfd11dc4f02daaa7feaa5d40cb8228ecb6d
data/README.md CHANGED
@@ -24,8 +24,8 @@ kodeco problems [--kind overdue|stuck_in_preauth|invoice_overdue|expiry_missed]
24
24
  kodeco flags --app guardpost|kerching|carolus
25
25
  kodeco shortlinks list [query] [--page N]
26
26
  kodeco shortlinks show <slug>
27
- kodeco shortlinks create <url> [--channels a,b] [--campaign NAME]
28
- kodeco shortlinks update <slug> --active=true|false
27
+ kodeco shortlinks create <url> [--channels a,b] [--campaign NAME] [--content VALUE] [--source NAME --medium NAME]
28
+ kodeco shortlinks update <slug> [--active=true|false] [--source NAME] [--medium NAME] [--content VALUE]
29
29
  ```
30
30
 
31
31
  `user` shows guardpost's customer summary, with kerching's and carolus's
@@ -42,7 +42,17 @@ print the `kodeco login --scopes` line to run, and send nothing. `show` and
42
42
  `update` take a slug or a short URL. Team members see and change only their
43
43
  own links. Admins see every link and the fuller click counts, and can use
44
44
  `--channels` (keys from carolus's `config/short_link_channels.yml`, such as
45
- `twitter`) and `--campaign`, which needs `--channels`.
45
+ `twitter`), `--campaign`, `--content` and `--source` with `--medium`.
46
+ Each channel gets a link, and so does `--source`, for a source that isn't a
47
+ channel, such as a newsletter we sponsor (`--source iosdevweekly --medium
48
+ email`). `--campaign` and `--content` need `--channels` or `--source`.
49
+ `--content` tells apart placements with the same destination, channel and
50
+ campaign; creating one again with the same content returns the existing
51
+ link. Without `--channels` or `--source` you get one link with no UTMs.
52
+ Admins can also retag a link with `update --source`, `--medium` and
53
+ `--content` (`--content ""` removes it). Its short URL stays the same, and
54
+ people get the new UTMs from their next click. carolus stores sources,
55
+ mediums and content in lower case.
46
56
 
47
57
  `login` uses guardpost's device-code flow: it prints a code and a link to
48
58
  approve it, and opens the link in a browser when run in a terminal. The
data/lib/periscope/cli.rb CHANGED
@@ -28,10 +28,12 @@ module Periscope
28
28
  flags --app guardpost|kerching|carolus Show an app's feature flags
29
29
  shortlinks list [query] [--page N] List kod.eco short links
30
30
  shortlinks show <slug> Show one short link and its clicks
31
- shortlinks create <url> [--channels a,b] [--campaign NAME]
31
+ shortlinks create <url> [--channels a,b] [--campaign NAME] [--content VALUE]
32
+ [--source NAME --medium NAME]
32
33
  Make short links to a kodeco.com URL
33
- shortlinks update <slug> --active=true|false
34
- Turn a short link on or off
34
+ shortlinks update <slug> [--active=true|false] [--source NAME]
35
+ [--medium NAME] [--content VALUE]
36
+ Turn a short link on or off, or retag it
35
37
 
36
38
  Every command takes --json (one JSON document on stdout, errors as JSON
37
39
  on stderr) and --debug (logs each request's method, URL and status).
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Periscope
4
+ module Commands
5
+ # WEB-8388. The --source, --medium and --content options of kodeco
6
+ # shortlinks create and update. carolus stores their values in lower case.
7
+ module ShortlinkTags
8
+ NEEDS_TAGGED_LINK = {
9
+ campaign: "--campaign needs --channels or --source: carolus uses it only for tagged links",
10
+ content: "--content needs --channels or --source"
11
+ }.freeze
12
+
13
+ private
14
+
15
+ def tag_options(parser, opts)
16
+ parser.on("--source NAME") { |v| opts[:source] = v }
17
+ parser.on("--medium NAME") { |v| opts[:medium] = v }
18
+ parser.on("--content VALUE") { |v| opts[:content] = v }
19
+ end
20
+
21
+ def tag_payload(opts)
22
+ { utm_source: opts[:source], utm_medium: opts[:medium], utm_content: opts[:content] }
23
+ end
24
+
25
+ # carolus would refuse these too; checking first sends nothing.
26
+ def check_create_options(opts)
27
+ tagged = opts[:channels] || opts[:source]
28
+ NEEDS_TAGGED_LINK.each { |key, message| raise UsageError, message if opts[key] && !tagged }
29
+ return if opts[:source].nil? == opts[:medium].nil?
30
+
31
+ raise UsageError, opts[:source] ? "--source needs --medium, such as email" : "--medium needs --source"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -4,13 +4,15 @@ module Periscope
4
4
  module Commands
5
5
  # kodeco shortlinks list, show, create and update: carolus's kod.eco short links.
6
6
  module Shortlinks
7
+ include ShortlinkTags
8
+
7
9
  SUBCOMMANDS = %w[list show create update].freeze
8
10
  PATH = "/api/v2/short_links"
9
11
  SLUG = /\A[a-z2-9]{5}\z/
10
- UTM_HEADERS = %w[SOURCE MEDIUM CAMPAIGN].freeze
12
+ UTM_HEADERS = %w[SOURCE MEDIUM CAMPAIGN CONTENT].freeze
11
13
  LIST_HEADERS = ["SHORT URL", "ACTIVE", "CLICKS", "7D", "BOTS", *UTM_HEADERS, "DESTINATION"].freeze
12
- TEAM_NOTE = "Short links are for the Kodeco team, and only admins can see or change other people's links " \
13
- "or use --channels and --campaign."
14
+ TEAM_NOTE = "Short links are for the Kodeco team, and only admins can see or change other people's links, " \
15
+ "use --channels, --campaign, --content, --source and --medium, or change a link's tags."
14
16
  RETRY_NOTE = "It may have been applied; running the same command again is safe."
15
17
 
16
18
  private
@@ -43,24 +45,29 @@ module Periscope
43
45
  opts = parse_options(positional: 1) do |parser, o|
44
46
  parser.on("--channels LIST", Array) { |v| o[:channels] = channels(v) }
45
47
  parser.on("--campaign NAME") { |v| o[:campaign] = v }
48
+ tag_options(parser, o)
46
49
  end
47
- raise UsageError, "--campaign needs --channels: carolus uses it only for channel links" if
48
- opts[:campaign] && !opts[:channels]
50
+ check_create_options(opts)
49
51
 
50
- payload = { destination_url: opts[:args].first, channels: opts[:channels], utm_campaign: opts[:campaign] }
52
+ payload = { destination_url: opts[:args].first, channels: opts[:channels], utm_campaign: opts[:campaign],
53
+ **tag_payload(opts) }
51
54
  links = carolus("shortlinks:write", write: true) { client.post_json("carolus", PATH, payload.compact) }["data"]
52
55
  emit(links) { create_text(links) }
53
56
  end
54
57
 
55
58
  def shortlinks_update
56
- opts = parse_options(positional: 1) { |parser, o| parser.on("--active BOOL", TrueClass) { |v| o[:active] = v } }
59
+ opts = parse_options(positional: 1) do |parser, o|
60
+ parser.on("--active BOOL", TrueClass) { |v| o[:active] = v }
61
+ tag_options(parser, o)
62
+ end
57
63
  slug = slug_arg(opts)
58
- raise UsageError, "update needs --active=true or --active=false" if opts[:active].nil?
64
+ payload = { active: opts[:active], **tag_payload(opts) }.compact
65
+ raise UsageError, "update needs --active=true|false, --source, --medium or --content" if payload.empty?
59
66
 
60
67
  link = carolus("shortlinks:write", slug: slug, write: true) do
61
- client.patch_json("carolus", "#{PATH}/#{slug}", { active: opts[:active] })
68
+ client.patch_json("carolus", "#{PATH}/#{slug}", payload)
62
69
  end["data"]
63
- emit(link) { ShortLinkText.new(link).updated }
70
+ emit(link) { ShortLinkText.new(link).updated(active_changed: payload.key?(:active)) }
64
71
  end
65
72
 
66
73
  def create_text(links)
@@ -6,9 +6,9 @@ module Periscope
6
6
  class ShortLinkText
7
7
  INACTIVE = "is now inactive. Visitors go to the kodeco.com home page."
8
8
 
9
- # The UTM source, medium and campaign, with empty values as nil so tables print "-".
9
+ # The UTM source, medium, campaign and content, with empty values as nil so tables print "-".
10
10
  def self.utm(link)
11
- %w[utm_source utm_medium utm_campaign].map { |key| link[key].to_s.empty? ? nil : link[key] }
11
+ %w[utm_source utm_medium utm_campaign utm_content].map { |key| link[key].to_s.empty? ? nil : link[key] }
12
12
  end
13
13
 
14
14
  def initialize(link)
@@ -20,8 +20,13 @@ module Periscope
20
20
  end
21
21
 
22
22
  # After a PATCH, which sends neither daily clicks nor bots.
23
- def updated
24
- ["#{@link['short_url']} #{@link['active'] ? 'is now active.' : INACTIVE}", *fields].join("\n")
23
+ def updated(active_changed: true)
24
+ status = if active_changed
25
+ @link["active"] ? "is now active." : INACTIVE
26
+ else
27
+ "is updated. From its next click it sends the UTMs below."
28
+ end
29
+ ["#{@link['short_url']} #{status}", *fields].join("\n")
25
30
  end
26
31
 
27
32
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Periscope
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/periscope.rb CHANGED
@@ -15,6 +15,7 @@ require_relative "periscope/short_link_text"
15
15
  require_relative "periscope/commands/user"
16
16
  require_relative "periscope/commands/kerching"
17
17
  require_relative "periscope/commands/flags"
18
+ require_relative "periscope/commands/shortlink_tags"
18
19
  require_relative "periscope/commands/shortlinks"
19
20
  require_relative "periscope/commands/logout"
20
21
  require_relative "periscope/cli"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kodeco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kodeco
@@ -23,6 +23,7 @@ files:
23
23
  - lib/periscope/commands/flags.rb
24
24
  - lib/periscope/commands/kerching.rb
25
25
  - lib/periscope/commands/logout.rb
26
+ - lib/periscope/commands/shortlink_tags.rb
26
27
  - lib/periscope/commands/shortlinks.rb
27
28
  - lib/periscope/commands/user.rb
28
29
  - lib/periscope/config.rb