Class: FamilySearch::Middleware::GedcomxParser

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/familysearch/middleware/response/familysearch_gedcomx.rb

Overview

Parse

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



7
8
9
10
11
12
# File 'lib/familysearch/middleware/response/familysearch_gedcomx.rb', line 7

def on_complete(env)
  content_type = env[:response_headers]['content-type']
  if ['application/x-gedcomx-atom+json','application/x-fs-v1+json'].include? content_type
    env[:body] = parse(env[:body], content_type) unless [204,304].index env[:status]
  end
end

#parse(body, content_type) ⇒ Object

The method that has MultiJson parse the json string.



15
16
17
18
19
20
21
22
# File 'lib/familysearch/middleware/response/familysearch_gedcomx.rb', line 15

def parse(body, content_type)
  case content_type
  when 'application/x-gedcomx-atom+json'
    FamilySearch::Gedcomx::AtomFeed.new body
  when 'application/x-fs-v1+json'
    FamilySearch::Gedcomx::FamilySearch.new body
  end
end