KerbalStuff 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +45 -1
  2. data/lib/KerbalStuff.rb +40 -6
  3. metadata +2 -2
data/README.md CHANGED
@@ -1,4 +1,48 @@
1
- KerbalStuffGem
1
+ KerbalStuff API Wrapper for Ruby
2
2
  ==============
3
3
 
4
4
  A simple Ruby API Wrapper for KerbalStuff
5
+
6
+
7
+ ## Gem Status
8
+ [![Gem Version](https://badge.fury.io/rb/KerbalStuff.png)](http://badge.fury.io/rb/KerbalStuff)
9
+
10
+
11
+ ## Install
12
+
13
+ You can install the gem like this:
14
+
15
+ gem install kerbalstuff
16
+
17
+
18
+ ## Examples
19
+
20
+ Here are some examples of how you can use the wrapper.
21
+
22
+ ```ruby
23
+ require 'kerbalstuff' # Require the Gem
24
+ ```
25
+
26
+ ```ruby
27
+ ks = KerbalStuff # Initialize the wrapper
28
+
29
+ ks.SearchMod(string) # will return a JSON object containing the search results
30
+ ks.SearchUser(string)
31
+ ks.User(string) # will return a JSON object containing information about the specified user
32
+ ks.Mod(integer) # will return a JSON object containing information about the specified mod
33
+ ks.GetLatestVersion(integer) # will return a JSON object containing information about the last version released for the specified mod.
34
+ ```
35
+
36
+ ## Documentation
37
+ For a *slightly* more detailed version of the gem's methods, take a look [here](http://rubydoc.info/gems/KerbalStuff/0.1.2/frames).
38
+
39
+
40
+ ## License
41
+
42
+ licensed under MIT License Copyright (c) 2008 Scott Chacon. See LICENSE for further details.
43
+
44
+
45
+ ## Contributing
46
+
47
+ If you want to contribute, feel free to do so!
48
+ Just fork the repo, make your changes, and then submit the pull-request.
@@ -11,7 +11,7 @@ module KerbalStuff
11
11
  MOD = "https://kerbalstuff.com/api/mod/"
12
12
 
13
13
  def self.get_https_response(url)
14
- @url = URI.parse(url)
14
+ @url = URI.parse(URI.escape(url))
15
15
  http = Net::HTTP.new(@url.host, @url.port)
16
16
  http.use_ssl = true
17
17
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -25,7 +25,7 @@ module KerbalStuff
25
25
  # Searches for mods with the specified keyword/phrase.
26
26
  #
27
27
  # @param query [String] the keyword/phrase to search for.
28
- # @return [String] A parsed JSON output containing the mods which were found.
28
+ # @return [Hash] A parsed JSON output containing the mods which were found.
29
29
  def self.SearchMod(query)
30
30
  response = get_https_response("#{SEARCH_MOD}#{query}")
31
31
  JSON.parse(response.body)
@@ -34,7 +34,7 @@ module KerbalStuff
34
34
  # Searches for users with the specified keyword/phrase.
35
35
  #
36
36
  # @param query [String] the keyword/phrase to search for.
37
- # @return [String] A parsed JSON output containing the users which were found.
37
+ # @return [Hash] A parsed JSON output containing the users which were found.
38
38
  def self.SearchUser(query)
39
39
  response = get_https_response("#{SEARCH_USER}#{query}")
40
40
  JSON.parse(response.body)
@@ -43,7 +43,7 @@ module KerbalStuff
43
43
  # Retrieves information about the specified user.
44
44
  #
45
45
  # @param username [String] the username to retrieve its information.
46
- # @return [String] A parsed JSON output containing the information about the user.
46
+ # @return [Hash] A parsed JSON output containing the information about the user.
47
47
  def self.User(username)
48
48
  raise "username cannot be nil" unless username.length > 0
49
49
 
@@ -54,7 +54,7 @@ module KerbalStuff
54
54
  # Retrieves the information about the specified mod.
55
55
  #
56
56
  # @param id [Fixnum] the id to retrieve its information.
57
- # @return [String] A parsed JSON output containing the information about the mod.
57
+ # @return [Hash] A parsed JSON output containing the information about the mod.
58
58
  def self.Mod(id)
59
59
  raise "id cannot be nil" unless id.is_a?(Integer) and id > 0
60
60
 
@@ -65,7 +65,7 @@ module KerbalStuff
65
65
  # Retrieves the information about the slast released version of the specified mod.
66
66
  #
67
67
  # @param username [Fixnum] the id to retrieve information of its latest version released.
68
- # @return [String] A parsed JSON output containing the information about the latest version released.
68
+ # @return [Hash] A parsed JSON output containing the information about the latest version released.
69
69
  def self.GetLatestVersion(id)
70
70
  raise "id cannot be nil" unless id.is_a?(Integer) and id > 0
71
71
 
@@ -73,4 +73,38 @@ module KerbalStuff
73
73
  JSON.parse(response.body)
74
74
  end
75
75
 
76
+ # Retrieves basic mod information - name, author, description, how many times it was downloaded, url to the mod and latest version.
77
+ #
78
+ # @param id [Fixnum] The id of the mod to retrieve information for.
79
+ # @return [Hash] A hash containing basic mod info.
80
+ def self.GetBasicModInfo(id)
81
+ oldHash = Mod(id)
82
+
83
+ modHash = Hash.new()
84
+ modHash["name"] = oldHash["name"]
85
+ modHash["author"] = oldHash["author"]
86
+ modHash["description"] = oldHash["short_description"]
87
+ modHash["downloads"] = oldHash["downloads"]
88
+ modHash["url"] = "https://kerbalstuff.com/mod/#{id}/}"
89
+ modHash["latest_version"] = oldHash["versions"][0]["friendly_version"]
90
+
91
+ modHash
92
+ end
93
+
94
+ # Retrieves basic user info - username, mods, irc nick and forum username.
95
+ #
96
+ # @param username [String] The user to gather information for.
97
+ # @return [Hash] A hash containing the basic user info.
98
+ def self.GetBasicUserInfo(string)
99
+ oldHash = User(string)
100
+
101
+ userHash = Hash.new()
102
+ userHash["username"] = oldHash["username"]
103
+ userHash["mods"] = oldHash["mods"]
104
+ userHash["ircNick"] = oldHash["ircNick"]
105
+ userHash["forumUsername"] = oldHash["forumUsername"]
106
+
107
+ userHash
108
+ end
109
+
76
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: KerbalStuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-17 00:00:00.000000000 Z
12
+ date: 2014-09-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple API wrapper for KerbalStuff
15
15
  email: rockytvbr@gmail.com