Class: Niffler::Maven

Inherits:
Object
  • Object
show all
Defined in:
lib/niffler/maven.rb

Constant Summary collapse

BASE_URL =
"http://search.maven.org/solrsearch/select?"
JSON_URL =
"&wt=json"
ROWS_URL =
"&rows=500"
ROW_URL =
"&rows=1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Maven

Returns a new instance of Maven.



13
14
15
16
17
18
19
# File 'lib/niffler/maven.rb', line 13

def initialize(opts)
  @group = opts.fetch(:group)
  @artifact = opts.fetch(:artifact)
  @version = opts.fetch(:version)
  @repository = opts.fetch(:repository)
  @packaging = opts.fetch(:packaging)
end

Instance Attribute Details

#artifactObject

Returns the value of attribute artifact.



7
8
9
# File 'lib/niffler/maven.rb', line 7

def artifact
  @artifact
end

#groupObject

Returns the value of attribute group.



7
8
9
# File 'lib/niffler/maven.rb', line 7

def group
  @group
end

#packagingObject

Returns the value of attribute packaging.



7
8
9
# File 'lib/niffler/maven.rb', line 7

def packaging
  @packaging
end

#repositoryObject

Returns the value of attribute repository.



7
8
9
# File 'lib/niffler/maven.rb', line 7

def repository
  @repository
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/niffler/maven.rb', line 7

def version
  @version
end

Class Method Details

.artifact_query(name) ⇒ Object

def self.artifacts_query



46
47
48
49
50
51
52
# File 'lib/niffler/maven.rb', line 46

def self.artifact_query(name)
  # build the query for artifacts specifying only one response
  url = BASE_URL+"q="+CGI::escape("a:\"#{name}\"")+JSON_URL+ROW_URL
  json = fetch_json(url)
  result = parse_json(json).last
  return result
end

.artifacts_query(name) ⇒ Object

def self.group_query



38
39
40
41
42
43
44
# File 'lib/niffler/maven.rb', line 38

def self.artifacts_query(name)
  # build the query for an artifact specifying 500 maximum responses
  url = BASE_URL+"q="+CGI::escape("a:\"#{name}\"")+JSON_URL+ROWS_URL
  json = fetch_json(url)
  results = parse_json(json)
  return results
end

.group_query(name) ⇒ Object

def find_by_group



29
30
31
32
33
34
35
36
# File 'lib/niffler/maven.rb', line 29

def self.group_query(name)
  # build the query for a group specifying only one response
  url = BASE_URL+"q="+CGI::escape(name)+JSON_URL+ROWS_URL
  # returns an array with a single entry
  json = fetch_json(url)
  result = parse_json(json).last
  return result
end

.groups_query(name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/niffler/maven.rb', line 21

def self.groups_query(name)
  # build the query for groups specifying 500 maximum responses
  url = BASE_URL+"q="+CGI::escape(name)+JSON_URL+ROWS_URL
  json = fetch_json(url)
  results = parse_json(json)
  return results
end

.hash_query(hash) ⇒ Object

def self.artifact_query



54
55
56
57
58
59
# File 'lib/niffler/maven.rb', line 54

def self.hash_query(hash)
  url = BASE_URL+"q="+CGI::escape("1:\"#{hash}\"")+JSON_URL+ROW_URL
  json = fetch_json(url)
  result = parse_hash_json(json)
  return result
end