Sha256: 2f0e98a71d5d358ff3c0b9dbfb78ed0ab8c09dd953a6991313fc4b8334d0dd1a

Contents?: true

Size: 775 Bytes

Versions: 2

Compression:

Stored size: 775 Bytes

Contents

require 'stratify-github/events'
require 'digest/md5'

class GitHubApiError < StandardError; end

module Stratify
  module GitHub
    module Translation

      def from_api_hash(api_hash)
        activity = Stratify::GitHub::Activity.new

        activity.event_type = api_hash['type']
        activity.url        = api_hash['url']
        activity.actor      = api_hash['actor']
        activity.created_at = Time.now()
        activity.checksum   = Digest::MD5.hexdigest(activity)

        begin
          clazz = Stratify::GitHub::Event.const_get(activity.event_type)
        rescue NameError
          raise GitHubApiError, "GitHub API passed unknown type #{activity.event_type}"
        end

        activity = clazz.make(activity, api_hash)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stratify-github-0.1.1 lib/stratify-github/translation.rb
stratify-github-0.1 lib/stratify-github/translation.rb