JsonDeserializer specific for Github objects.

Introduced properties

fun url_heuristic(raw: Map[String, nullable Object]): nullable String

github :: GithubDeserializer :: url_heuristic

Match url property in object to a class name
fun url_patterns: Map[Regex, String]

github :: GithubDeserializer :: url_patterns

Url patterns to class names
protected fun url_patterns=(url_patterns: Map[Regex, String])

github :: GithubDeserializer :: url_patterns=

Url patterns to class names

Redefined properties

redef type SELF: GithubDeserializer

github $ GithubDeserializer :: SELF

Type of this instance, automatically specialized in every class
redef fun class_name_heuristic(raw: Map[String, nullable Object]): nullable String

github $ GithubDeserializer :: class_name_heuristic

User customizable heuristic to infer the name of the Nit class to deserialize json_object
redef fun class_name_heuristic(json_object: Map[String, nullable Object]): nullable String

github :: events $ GithubDeserializer :: class_name_heuristic

User customizable heuristic to infer the name of the Nit class to deserialize json_object
redef fun deserialize_class(name: Text): nullable Object

github $ GithubDeserializer :: deserialize_class

Deserialize the next available object as an instance of class_name

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun accept(dynamic_type: Text, static_type: nullable Text): Bool

serialization :: SafeDeserializer :: accept

Should self accept to deserialize an instance of dynamic_type for an attribute wuth static_type?
protected fun accept_json_serializer(v: JsonSerializer)

serialization :: Serializable :: accept_json_serializer

Refinable service to customize the serialization of this class to JSON
protected fun accept_msgpack_attribute_counter(v: AttributeCounter)

serialization :: Serializable :: accept_msgpack_attribute_counter

Hook to customize the behavior of the AttributeCounter
protected fun accept_msgpack_serializer(v: MsgPackSerializer)

serialization :: Serializable :: accept_msgpack_serializer

Hook to customize the serialization of this class to MessagePack
protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)

serialization :: Serializable :: add_to_bundle

Called by []= to dynamically choose the appropriate method according
fun attributes_path: Array[String]

json :: JsonDeserializer :: attributes_path

Names of the attributes from the root to the object currently being deserialized
protected fun attributes_path=(attributes_path: Array[String])

json :: JsonDeserializer :: attributes_path=

Names of the attributes from the root to the object currently being deserialized
fun cache: DeserializerCache

serialization :: CachingDeserializer :: cache

Cache of known objects
fun cache=(cache: DeserializerCache)

serialization :: CachingDeserializer :: cache=

Cache of known objects
fun check_subtypes: Bool

serialization :: SafeDeserializer :: check_subtypes

Should objects be checked if they a subtype of the static type before deserialization?
fun check_subtypes=(check_subtypes: Bool)

serialization :: SafeDeserializer :: check_subtypes=

Should objects be checked if they a subtype of the static type before deserialization?
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
protected fun class_name_heuristic(json_object: Map[String, nullable Object]): nullable String

json :: JsonDeserializer :: class_name_heuristic

User customizable heuristic to infer the name of the Nit class to deserialize json_object
fun core_serialize_to(serializer: Serializer)

serialization :: Serializable :: core_serialize_to

Actual serialization of self to serializer
abstract fun deserialize(static_type: nullable String): nullable Object

serialization :: Deserializer :: deserialize

Deserialize and return an object, storing errors in the attribute errors
abstract fun deserialize_attribute(name: String, static_type: nullable String): nullable Object

serialization :: Deserializer :: deserialize_attribute

Deserialize the attribute with name from the object open for deserialization
fun deserialize_attribute_missing: Bool

serialization :: Deserializer :: deserialize_attribute_missing

Was the attribute queried by the last call to deserialize_attribute missing?
protected fun deserialize_attribute_missing=(deserialize_attribute_missing: Bool)

serialization :: Deserializer :: deserialize_attribute_missing=

Was the attribute queried by the last call to deserialize_attribute missing?
protected fun deserialize_class(class_name: Text): nullable Object

serialization :: Deserializer :: deserialize_class

Deserialize the next available object as an instance of class_name
protected fun deserialize_class_intern(class_name: Text): nullable Object

serialization :: Deserializer :: deserialize_class_intern

Generated service to deserialize the next available object as an instance of class_name
fun errors: Array[Error]

serialization :: Deserializer :: errors

Errors encountered in the last call to deserialize
protected fun errors=(errors: Array[Error])

serialization :: Deserializer :: errors=

Errors encountered in the last call to deserialize
init from_deserializer(deserializer: Deserializer)

serialization :: Serializable :: from_deserializer

Create an instance of this class from the deserializer
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun just_opened_id: nullable Int

json :: JsonDeserializer :: just_opened_id

Last encountered object reference id.
protected fun just_opened_id=(just_opened_id: nullable Int)

json :: JsonDeserializer :: just_opened_id=

Last encountered object reference id.
fun keep_going: nullable Bool

serialization :: Deserializer :: keep_going

Should self keep trying to deserialize an object after an error?
fun keep_going=(keep_going: nullable Bool)

serialization :: Deserializer :: keep_going=

Should self keep trying to deserialize an object after an error?
protected fun msgpack_extra_array_items: Int

serialization :: Serializable :: msgpack_extra_array_items

Hook to request a larger than usual metadata array
abstract fun notify_of_creation(new_object: Object)

serialization :: Deserializer :: notify_of_creation

Register a newly allocated object (even if not completely built)
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun serialize_msgpack(plain: nullable Bool): Bytes

serialization :: Serializable :: serialize_msgpack

Serialize self to MessagePack bytes
fun serialize_to(serializer: Serializer)

serialization :: Serializable :: serialize_to

Serialize self to serializer
fun serialize_to_json(plain: nullable Bool, pretty: nullable Bool): String

serialization :: Serializable :: serialize_to_json

Serialize self to JSON
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_json: String

serialization :: Serializable :: to_json

Serialize self to plain JSON
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_pretty_json: String

serialization :: Serializable :: to_pretty_json

Serialize self to plain pretty JSON
fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun url_heuristic(raw: Map[String, nullable Object]): nullable String

github :: GithubDeserializer :: url_heuristic

Match url property in object to a class name
fun url_patterns: Map[Regex, String]

github :: GithubDeserializer :: url_patterns

Url patterns to class names
protected fun url_patterns=(url_patterns: Map[Regex, String])

github :: GithubDeserializer :: url_patterns=

Url patterns to class names
fun whitelist: Array[Text]

serialization :: SafeDeserializer :: whitelist

Accepted parameterized classes to deserialize
protected fun whitelist=(whitelist: Array[Text])

serialization :: SafeDeserializer :: whitelist=

Accepted parameterized classes to deserialize
package_diagram github::GithubDeserializer GithubDeserializer json::JsonDeserializer JsonDeserializer github::GithubDeserializer->json::JsonDeserializer serialization::CachingDeserializer CachingDeserializer json::JsonDeserializer->serialization::CachingDeserializer serialization::SafeDeserializer SafeDeserializer json::JsonDeserializer->serialization::SafeDeserializer ...serialization::CachingDeserializer ... ...serialization::CachingDeserializer->serialization::CachingDeserializer ...serialization::SafeDeserializer ... ...serialization::SafeDeserializer->serialization::SafeDeserializer

Ancestors

abstract class CachingDeserializer

serialization :: CachingDeserializer

A Deserializer with a cache
abstract class Deserializer

serialization :: Deserializer

Abstract deserialization service
interface Object

core :: Object

The root of the class hierarchy.
class SafeDeserializer

serialization :: SafeDeserializer

Deserialization engine limiting which types can be deserialized
interface Serializable

serialization :: Serializable

Instances of this class can be passed to Serializer::serialize

Parents

class JsonDeserializer

json :: JsonDeserializer

Deserializer from a Json string.

Class definitions

github $ GithubDeserializer
# JsonDeserializer specific for Github objects.
class GithubDeserializer
	super JsonDeserializer

	private var pattern_base = "https://api.github.com"

	# Url patterns to class names
	var url_patterns: Map[Regex, String] is lazy do
		var map = new HashMap[Regex, String]
		map["{pattern_base}/users/[^/]*$".to_re] = "User"
		map["{pattern_base}/repos/[^/]*/[^/]*$".to_re] = "Repo"
		map["{pattern_base}/repos/[^/]*/[^/]*/labels/[^/]+$".to_re] = "Label"
		map["{pattern_base}/repos/[^/]*/[^/]*/milestones/[0-9]+$".to_re] = "Milestone"
		map["{pattern_base}/repos/[^/]*/[^/]*/issues/[0-9]+$".to_re] = "Issue"
		map["{pattern_base}/repos/[^/]*/[^/]*/issues/comments/[0-9]+$".to_re] = "IssueComment"
		map["{pattern_base}/repos/[^/]*/[^/]*/issues/events/[0-9]+$".to_re] = "IssueEvent"
		map["{pattern_base}/repos/[^/]*/[^/]*/pulls/[0-9]+$".to_re] = "PullRequest"
		map["{pattern_base}/repos/[^/]*/[^/]*/pulls/comments/[0-9]+$".to_re] = "PullComment"
		map["{pattern_base}/repos/[^/]*/[^/]*/comments/[0-9]+$".to_re] = "CommitComment"
		map["{pattern_base}/repos/[^/]*/[^/]*/commits/[a-f0-9]+$".to_re] = "Commit"
		map["{pattern_base}/repos/[^/]*/[^/]*/commits/[a-f0-9]+/status$".to_re] = "CommitStatus"
		map["{pattern_base}/repos/[^/]*/[^/]*/statuses/[a-f0-9]+$".to_re] = "RepoStatus"
		return map
	end

	# Match `url` property in object to a class name
	fun url_heuristic(raw: Map[String, nullable Object]): nullable String do
		if not raw.has_key("url") then return null

		var url = raw["url"].as(String)
		for re, class_name in url_patterns do
			if url.has(re) then return class_name
		end
		return null
	end

	redef fun class_name_heuristic(raw) do
		# Try with url
		var class_name = url_heuristic(raw)
		if class_name != null then return class_name

		# print raw.serialize_to_json(true, true) # debug

		# Use properties heuristics
		if raw.has_key("name") and raw.has_key("commit") then
			return "Branch"
		else if raw.has_key("total_count") and raw.has_key("items") then
			return "SearchResults"
		else if raw.has_key("total") and raw.has_key("weeks") then
			return "ContributorStats"
		else if raw.has_key("a") and raw.has_key("d") and raw.has_key("c") then
			return "ContributorWeek"
		end
		return null
	end

	redef fun deserialize_class(name) do
		if name == "Issue" then
			var issue = super.as(Issue)
			if path.last.has_key("pull_request") then
				issue.is_pull_request = true
			end
			return issue
		else if name == "Commit" then
			var commit = super.as(Commit)
			var git_commit = commit.commit
			if git_commit != null then commit.message = git_commit.message
			return commit
		end
		return super
	end
end
lib/github/api.nit:1075,1--1146,3

github :: events $ GithubDeserializer
redef class GithubDeserializer

	redef fun class_name_heuristic(json_object) do
		if json_object.has_key("action") and json_object.has_key("commit") and json_object.has_key("comment") then
			return "CommitCommentEvent"
		else if json_object.has_key("ref") and json_object.has_key("master_branch") then
			return "CreateEvent"
		else if json_object.has_key("ref") and json_object.has_key("ref_type") then
			return "DeleteEvent"
		else if json_object.has_key("action") and json_object.has_key("sha") then
			return "DeploymentEvent"
		else if json_object.has_key("action") and json_object.has_key("state") then
			return "DeploymentStatusEvent"
		else if json_object.has_key("action") and json_object.has_key("forkee") then
			return "ForkEvent"
		else if json_object.has_key("action") and json_object.has_key("issue") and json_object.has_key("comment") then
			return "IssueCommentEvent"
		else if json_object.has_key("action") and json_object.has_key("issue") then
			return "IssuesEvent"
		else if json_object.has_key("action") and json_object.has_key("member") then
			return "MemberEvent"
		else if json_object.has_key("action") and json_object.has_key("number") then
			return "PullRequestEvent"
		else if json_object.has_key("action") and json_object.has_key("pull") and json_object.has_key("comment") then
			return "PullRequestPullCommentEvent"
		else if json_object.has_key("head_commit") and json_object.has_key("commits") then
			return "PushEvent"
		else if json_object.has_key("action") and json_object.has_key("branches") then
			return "StatusEvent"
		else if json_object.has_key("action") and json_object.has_key("issue") then
			return "GithubEvent"
		end
		return super
	end
end
lib/github/events.nit:247,1--281,3