Class: Freshmeat

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/freshmeat.rb,
lib/freshmeat/data.rb

Overview

Copyright © 2011 Matthew Stump

data.rb

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Defined Under Namespace

Classes: Comment, Data, PartialProject, Project, Release, Screenshot, Tag, URL, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_code) ⇒ Freshmeat

Auth code is the API authorization code provided by freshmeat



38
39
40
# File 'lib/freshmeat.rb', line 38

def initialize(auth_code)
  @auth_code = auth_code
end

Instance Attribute Details

#auth_codeObject (readonly)

Returns the value of attribute auth_code.



35
36
37
# File 'lib/freshmeat.rb', line 35

def auth_code
  @auth_code
end

Instance Method Details

#comments(project) ⇒ Object

Fetch the list of comments for the project specified by the project permalink



70
71
72
# File 'lib/freshmeat.rb', line 70

def comments(project)
  @comments ||= get("/projects/#{project}/comments.json").map {|x| Comment.new(x["comment"])}
end

#project(project) ⇒ Object

Get project by the permalink



43
44
45
# File 'lib/freshmeat.rb', line 43

def project(project)
  @project = Project.new(get("/projects/#{project}.json")["project"])
end

#recently_released_projectsObject

Get the most recently released projects, this list corresponds with the Freshmeat front page and RSS feed. The data returned by the frontpage API is inconsistant with that returned by the data API. To draw attention to this fact we use the class PartialProject to signify that you only have access to a subset of the normal attributes. This subset consists of:

* permalink
* fid (Freshmeat object id)
* name
* oneliner
* description
* license_list
* recent_releases which is limited to the most recent release


60
61
62
63
64
65
66
67
# File 'lib/freshmeat.rb', line 60

def recently_released_projects()
  get("/index.json").map { |x|
    p = x["release"]["project"]
    x.delete("project")
    p["recent_releases"] = [x["release"]]
    PartialProject.new(p)
  }
end

#releases(project) ⇒ Object

Fetch the list of releases for the project specified by the project permalink



75
76
77
# File 'lib/freshmeat.rb', line 75

def releases(project)
  @releases ||= get("/projects/#{project}/releases.json").map {|x| Release.new(x["release"])}
end

#screenshots(project) ⇒ Object

Fetch the list of screenshots for the project specified by the project permalink



80
81
82
# File 'lib/freshmeat.rb', line 80

def screenshots(project)
  @screenshots ||= get("/projects/#{project}/screenshots.json").map {|x| Screenshot.new(x["screenshot"])}
end

#search(query, page = 1, args = {}) ⇒ Object

Search for project by string with optional pagination



101
102
103
# File 'lib/freshmeat.rb', line 101

def search(query, page=1, args={})
  @results ||= get("/search.json", args.merge({:q => query, :page => page}))["projects"].map {|x| Project.new(x["project"])}
end

#tag(tag) ⇒ Object

Fetch the list of projects matching tag



90
91
92
93
# File 'lib/freshmeat.rb', line 90

def tag(tag)
  r = get("/tags/#{tag}.json")
  @tags ||= Tag.new(r["tag"], r["projects"].map {|x| Project.new(x)})
end

#tagsObject

Fetch the entire list of tags



96
97
98
# File 'lib/freshmeat.rb', line 96

def tags()
  @tags ||= get("/tags/all.json").map {|x| Tag.new(x["tag"])}
end

#urls(project) ⇒ Object

Fetch the list of URLs for the project specified by the project permalink



85
86
87
# File 'lib/freshmeat.rb', line 85

def urls(project)
  @urls ||= get("/projects/#{project}/urls.json").map {|x| URL.new(x["url"])}
end