Module: Stratify::GitHub::Translation

Included in:
Activity
Defined in:
lib/stratify-github/translation.rb

Instance Method Summary collapse

Instance Method Details

#from_api_hash(api_hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stratify-github/translation.rb', line 10

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 = api_hash['created_at']

  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