Class: Fastlane::Actions::BitlyAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/bitly/actions/bitly_action.rb

Defined Under Namespace

Modules: SharedValues

Class Method Summary collapse

Class Method Details

.authorsObject



48
49
50
# File 'lib/fastlane/plugin/bitly/actions/bitly_action.rb', line 48

def self.authors
  ["Thang Nguyen"]
end

.available_optionsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/bitly/actions/bitly_action.rb', line 61

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :token,
                            env_name: "",
                         description: "Bitly Access API Token",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :group_guid,
                            env_name: "",
                         description: "Bitly Group guid",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :long_url,
                            env_name: "",
                         description: "Long link",
                            optional: false,
                                type: String)
  ]
end

.descriptionObject



44
45
46
# File 'lib/fastlane/plugin/bitly/actions/bitly_action.rb', line 44

def self.description
  "create bit.ly short link from url"
end

.detailsObject



56
57
58
59
# File 'lib/fastlane/plugin/bitly/actions/bitly_action.rb', line 56

def self.details
  # Optional:
  "create bit.ly short link"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
# File 'lib/fastlane/plugin/bitly/actions/bitly_action.rb', line 81

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  [:ios, :android].include?(platform)
  true
end

.return_valueObject



52
53
54
# File 'lib/fastlane/plugin/bitly/actions/bitly_action.rb', line 52

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fastlane/plugin/bitly/actions/bitly_action.rb', line 13

def self.run(params)
  UI.message("The bitly plugin is working!")
  token = params[:token]
  group_guid = params[:group_guid]
  long_url = params[:long_url]

  UI.message("token: #{token} group_guid: #{group_guid} long_url: #{long_url}" )
  response = Faraday.post(
    "https://api-ssl.bitly.com/v4/shorten",
    {
      group_guid: group_guid,
      domain: "bit.ly",
      long_url: long_url,
    }.to_json,
    {
      "Content-Type" => "application/json",
      "Authorization": "Bearer #{token}"
    }
  )
  # puts(response.body)
  json = JSON.parse(response.body)
  shortlink = json['link']
  if shortlink
    Actions.lane_context[SharedValues::BITLY_SHORTLINK_OUTPUT] = shortlink
    ENV[SharedValues::BITLY_SHORTLINK_OUTPUT.to_s] = shortlink
  else
    UI.message("Can not generate short link")
  end

end