Sha256: 2d6e3f4339330e1b62b2b773c2fbd582a1c3a572b0981ceb7f7f849ea9bd04ee

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require "net/http"
require "json"
require "action_view"
require_relative "../utils"

module DevOrbit
  module Interactions
    class Follower
      def initialize(id:, name:, username:, url:, workspace_id:, api_key:)
        @id = id
        @name = name
        @username = username
        @url = url
        @workspace_id = workspace_id
        @api_key = api_key

        after_initialize!
      end

      def after_initialize!
        url = URI("https://app.orbit.love/api/v1/#{@workspace_id}/members")

        http = Net::HTTP.new(url.host, url.port)
        http.use_ssl = true
        req = Net::HTTP::Post.new(url)
        req["Accept"] = "application/json"
        req["Content-Type"] = "application/json"
        req["Authorization"] = "Bearer #{@api_key}"
        req["User-Agent"] = "community-ruby-dev-orbit/#{DevOrbit::VERSION}"

        req.body = construct_body

        req.body = req.body.to_json

        response = http.request(req)

        JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
      end

      def construct_body
        {
          member: {
            name: @name.include?("_") ? @name.split("_").map(&:capitalize).join(" ") : @name,
            devto: @username
          }
        }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dev_orbit-0.5.2 lib/dev_orbit/interactions/follower.rb
dev_orbit-0.5.1 lib/dev_orbit/interactions/follower.rb
dev_orbit-0.5.0 lib/dev_orbit/interactions/follower.rb
dev_orbit-0.4.1 lib/dev_orbit/interactions/follower.rb
dev_orbit-0.4.0 lib/dev_orbit/interactions/follower.rb
dev_orbit-0.3.0 lib/dev_orbit/interactions/follower.rb