Class: DevOrbit::Interactions::Follower
- Inherits:
-
Object
- Object
- DevOrbit::Interactions::Follower
- Defined in:
- lib/dev_orbit/interactions/follower.rb
Instance Method Summary collapse
- #after_initialize! ⇒ Object
- #construct_body ⇒ Object
-
#initialize(id:, name:, username:, url:, workspace_id:, api_key:) ⇒ Follower
constructor
A new instance of Follower.
Constructor Details
#initialize(id:, name:, username:, url:, workspace_id:, api_key:) ⇒ Follower
Returns a new instance of Follower.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dev_orbit/interactions/follower.rb', line 11 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 |
Instance Method Details
#after_initialize! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dev_orbit/interactions/follower.rb', line 22 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 |
#construct_body ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/dev_orbit/interactions/follower.rb', line 42 def construct_body { member: { name: @name.include?("_") ? @name.split("_").map(&:capitalize).join(" ") : @name, devto: @username } } end |