Class: DevOrbit::Orbit
- Inherits:
-
Object
- Object
- DevOrbit::Orbit
- Defined in:
- lib/dev_orbit/orbit.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(type:, data:, workspace_id:, api_key:, historical_import: false, last_orbit_member_timestamp: nil) ⇒ Orbit
constructor
A new instance of Orbit.
Constructor Details
#initialize(type:, data:, workspace_id:, api_key:, historical_import: false, last_orbit_member_timestamp: nil) ⇒ Orbit
Returns a new instance of Orbit.
9 10 11 12 13 14 15 16 17 |
# File 'lib/dev_orbit/orbit.rb', line 9 def initialize(type:, data:, workspace_id:, api_key:, historical_import: false, last_orbit_member_timestamp: nil) @type = type @data = data @workspace_id = workspace_id @api_key = api_key @historical_import = historical_import @last_orbit_activity_timestamp = (type) @last_orbit_member_timestamp = end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dev_orbit/orbit.rb', line 19 def call if @type == "comments" times = 0 @data[:comments].each do |comment| unless @historical_import && @last_orbit_activity_timestamp next if (comment["created_at"] || comment[:created_at]) < @last_orbit_activity_timestamp unless @last_orbit_activity_timestamp.nil? end if @last_orbit_activity_timestamp && @historical_import == false next if (comment["created_at"] || comment[:created_at]) < @last_orbit_activity_timestamp end times += 1 DevOrbit::Interactions::Comment.new( article_title: @data.transform_keys(&:to_sym)[:title], comment: comment.transform_keys(&:to_sym), url: @data[:url], workspace_id: @workspace_id, api_key: @api_key ) end output = "Sent #{times} new DEV comments to your Orbit workspace" puts output return output end if @type == "followers" counter = 0 @data[:followers].each do |follower| next if follower.nil? || follower.empty? unless @historical_import && @last_orbit_member_timestamp next if follower["created_at"] < @last_orbit_member_timestamp unless @last_orbit_member_timestamp.nil? end if @last_orbit_member_timestamp && @historical_import == false next if follower["created_at"] < @last_orbit_member_timestamp end sleep(20) if counter % 100 == 0 && counter != 0 # API rate limiting DevOrbit::Interactions::Follower.new( id: follower["id"], name: follower["name"], username: follower["username"], url: follower["path"], workspace_id: @workspace_id, api_key: @api_key ) counter += 1 end output = "Sent #{counter} new followers to Orbit" puts output return output end end |