KerbalStuff 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+
4
+ # Custom for Visual Studio
5
+ *.cs diff=csharp
6
+ *.sln merge=union
7
+ *.csproj merge=union
8
+ *.vbproj merge=union
9
+ *.fsproj merge=union
10
+ *.dbproj merge=union
11
+
12
+ # Standard to msysgit
13
+ *.doc diff=astextplain
14
+ *.DOC diff=astextplain
15
+ *.docx diff=astextplain
16
+ *.DOCX diff=astextplain
17
+ *.dot diff=astextplain
18
+ *.DOT diff=astextplain
19
+ *.pdf diff=astextplain
20
+ *.PDF diff=astextplain
21
+ *.rtf diff=astextplain
22
+ *.RTF diff=astextplain
@@ -0,0 +1,74 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ # =========================
37
+ # Operating System Files
38
+ # =========================
39
+
40
+ # OSX
41
+ # =========================
42
+
43
+ .DS_Store
44
+ .AppleDouble
45
+ .LSOverride
46
+
47
+ # Icon must ends with two \r.
48
+ Icon
49
+
50
+ # Thumbnails
51
+ ._*
52
+
53
+ # Files that might appear on external disk
54
+ .Spotlight-V100
55
+ .Trashes
56
+
57
+ # Windows
58
+ # =========================
59
+
60
+ # Windows image file caches
61
+ Thumbs.db
62
+ ehthumbs.db
63
+
64
+ # Folder config file
65
+ Desktop.ini
66
+
67
+ # Recycle Bin used on file shares
68
+ $RECYCLE.BIN/
69
+
70
+ # Windows Installer files
71
+ *.cab
72
+ *.msi
73
+ *.msm
74
+ *.msp
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kerbalstuff/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'KerbalStuff'
7
+ s.version = KerbalStuff::VERSION
8
+ s.summary = "KerbalStuff"
9
+ s.description = "A simple API wrapper for KerbalStuff"
10
+ s.authors = ["Alexandre Oliveira"]
11
+ s.email = 'rockytvbr@gmail.com'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.require_paths = ["lib"]
15
+
16
+ s.homepage =
17
+ 'https://github.com/RockyTV/KerbalStuffGem'
18
+ s.license = 'MIT'
19
+ s.extra_rdoc_files = ['README.md']
20
+ s.required_ruby_version = '>= 1.9.3'
21
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) {{{year}}} {{{fullname}}}
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -4,10 +4,11 @@ require 'uri'
4
4
 
5
5
  module KerbalStuff
6
6
 
7
- api_url = "https://kerbalstuff.com/api"
8
- user_url = "https://kerbalstuff.com/api/user/"
9
- mod_url = "https://kerbalstuff.com/api/mod/"
10
-
7
+ autoload :VERSION, 'kerbalstuff/version'
8
+ autoload :Mod, 'kerbalstuff/mod'
9
+ autoload :ModVerison, 'kerbalstuff/mod'
10
+ autoload :User, 'kerbalstuff/user'
11
+
11
12
  def self.get_https_response(url)
12
13
  @url = URI.parse(URI.escape(url))
13
14
  http = Net::HTTP.new(@url.host, @url.port)
@@ -30,125 +31,78 @@ module KerbalStuff
30
31
  else
31
32
  return json
32
33
  end
34
+ else
35
+ return json
33
36
  end
34
37
  end
35
38
 
36
39
  # Searches for mods with the specified keyword/phrase.
37
40
  #
38
41
  # @param query [String] the keyword/phrase to search for.
39
- # @return [Hash] A parsed JSON output containing the mods which were found. Will return a [String] if no results were found.
42
+ # @return [Array] An array containing the results found. If no result was found, will return a String.
40
43
  def self.search_mod(query)
41
44
  res = get_json("https://kerbalstuff.com/api/search/mod?query=#{query}")
42
45
 
46
+ resArr = []
47
+
43
48
  if res.length == 0
44
49
  return "No results were found for '#{query}'."
45
50
  else
46
- return res
51
+ res.each do |mod|
52
+ resArr.push(Mod.new(mod))
53
+ end
54
+ return resArr
47
55
  end
48
56
  end
49
57
 
50
58
  # Searches for users with the specified keyword/phrase.
51
59
  #
52
60
  # @param query [String] the keyword/phrase to search for.
53
- # @return [Hash] A parsed JSON output containing the users which were found. Will return a [String] if no results were found.
61
+ # @return [Array] An array containing the results found. If no result was found, will return a String.
54
62
  def self.search_user(query)
55
63
  res = get_json("https://kerbalstuff.com/api/search/user?query=#{query}")
56
64
 
65
+ resArr = []
66
+
57
67
  if res.length == 0
58
68
  return "No results were found for '#{query}'."
59
69
  else
60
- return res
61
- end
62
- end
63
-
64
- # Retrieves information about the specified user.
65
- #
66
- # @param username [String] the username to retrieve its information.
67
- # @return [Hash] A parsed JSON output containing the information about the user. Will return a [String] if no users were found.
68
- def self.user(username)
69
- raise "username cannot be nil" unless username.length > 0
70
-
71
- res = get_json("https://kerbalstuff.com/api/user/#{username}")
72
-
73
- if res.include? 'error'
74
- return res[1]
75
- else
76
- return res
77
- end
78
- end
79
-
80
- # Retrieves the information about the specified mod.
81
- #
82
- # @param id [Fixnum] the id to retrieve its information.
83
- # @return [Hash] A parsed JSON output containing the information about the mod. Will return a [String] if no mods were found.
84
- def self.mod(id)
85
- raise "id cannot be nil" unless id.is_a?(Integer)
86
-
87
- res = get_json("https://kerbalstuff.com/api/mod/#{id}")
88
-
89
- if res.include? 'error'
90
- return res[1]
91
- else
92
- return res
70
+ res.each do |user|
71
+ resArr.push(User.new(user))
72
+ end
73
+ return resArr
93
74
  end
94
75
  end
95
76
 
96
- # Retrieves the information about the last released version of the specified mod.
77
+ # Retrieves the specified mod information.
97
78
  #
98
- # @param username [Fixnum] the id to retrieve information of its latest version released.
99
- # @return [Hash] A parsed JSON output containing the information about the latest version released.
100
- def self.get_latest_version(id)
101
- raise "id cannot be nil" unless id.is_a?(Integer)
102
-
103
- res = get_json("https://kerbalstuff.com/api/mod/#{id}/latest")
79
+ # @param id [Integer] the id of the mod to retrieve information for.
80
+ # @return [Mod] A Mod object containing the information about the mod.
81
+ def self.get_mod(id)
82
+ raise "id must be an Integer" unless id.is_a?(Integer)
104
83
 
105
- if res.include? 'error'
106
- return res[1]
107
- else
108
- return res
109
- end
84
+ return Mod.new(get_json("https://kerbalstuff.com/api/mod/#{id}"))
110
85
  end
111
86
 
112
- # Retrieves basic mod information - name, author, description, how many times it was downloaded, url to the mod and latest version.
87
+ # Retrieves the specified user information.
113
88
  #
114
- # @param id [Fixnum] The id of the mod to retrieve information for.
115
- # @return [Hash] A hash containing basic mod info.
116
- def self.get_basic_mod_info(id)
117
- oldHash = mod(id)
89
+ # @param username [String] the username of the user to retrieve information for.
90
+ # @return [User] A User object containing the information about the user.
91
+ def self.get_user(username)
92
+ raise "username must be a String" unless username.is_a?(String)
93
+ raise "username cannot be an empty string" unless username.length > 0
118
94
 
119
- if oldHash.is_a?(String)
120
- return oldHash
121
- else
122
- modHash = Hash.new()
123
- modHash["name"] = oldHash["name"]
124
- modHash["author"] = oldHash["author"]
125
- modHash["description"] = oldHash["short_description"]
126
- modHash["downloads"] = oldHash["downloads"]
127
- modHash["url"] = "https://kerbalstuff.com/mod/#{id}/}"
128
- modHash["latest_version"] = oldHash["versions"][0]["friendly_version"]
129
-
130
- return modHash
131
- end
95
+ return User.new(get_json("https://kerbalstuff.com/api/user/#{username}"))
132
96
  end
133
97
 
134
- # Retrieves basic user info - username, mods, irc nick and forum username.
98
+ # Retrieves the latest version of the specified mod.
135
99
  #
136
- # @param username [String] The user to gather information for.
137
- # @return [Hash] A hash containing the basic user info.
138
- def self.get_basic_user_info(username)
139
- oldHash = user(username)
100
+ # @param id [Integer] the id of the mod to retrieve the latest version released.
101
+ # @return [ModVersion] A ModVersion object containing information about the version.
102
+ def self.get_latest_mod_version(id)
103
+ raise "id must be an Integer" unless id.is_a?(Integer)
140
104
 
141
- if oldHash.is_a?(String)
142
- return oldHash
143
- else
144
- userHash = Hash.new()
145
- userHash["username"] = oldHash["username"]
146
- userHash["mods"] = oldHash["mods"]
147
- userHash["ircNick"] = oldHash["ircNick"]
148
- userHash["forumusername"] = oldHash["forumusername"]
149
-
150
- return userHash
151
- end
105
+ return ModVersion.new(get_json("https://kerbalstuff.com/api/mod/#{id}/latest"))
152
106
  end
153
107
 
154
108
  end
@@ -0,0 +1,54 @@
1
+ module KerbalStuff
2
+ class Mod
3
+
4
+ attr_reader :json
5
+
6
+ def initialize json
7
+ @json = json
8
+
9
+ @name = @json['name']
10
+ @background = @json['background']
11
+ @author = @json['author']
12
+ @downloads = @json['downloads']
13
+ @id = @json['id']
14
+ @short_description = @json['short_description']
15
+ @description_html = @json['description_html']
16
+ @followers = @json['followers']
17
+ @default_version_id = @json['default_version_id']
18
+ @description = @json['description']
19
+
20
+ if @json.has_key?('versions')
21
+ @versions = []
22
+ if @json['versions'].length > 0
23
+ @json['versions'].each do |v|
24
+ @versions.push(ModVersion.new(v))
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ def to_s
32
+ "Mod:\nname=#{@name}\nbackground=#{@background}\nauthor=#{@author}\ndownloads=#{@downloads}\nid=#{@id}\nshort_description=\"#{@short_description}\"\nversions=#{@versions}\ndescription_html=\"#{@description_html}\"\nfollowers=#{@followers}\ndefault_version_id=#{@default_version_id}\ndescription=\"#{@description}\"\n"
33
+ end
34
+ end
35
+
36
+ class ModVersion
37
+
38
+ attr_reader :json
39
+
40
+ def initialize json
41
+ @json = json
42
+
43
+ @version = @json['friendly_version']
44
+ @download_path = @json['download_path']
45
+ @id = @json['id']
46
+ @ksp_version = @json['ksp_version']
47
+ @changelog = @json['changelog']
48
+ end
49
+
50
+ def to_s
51
+ "ModVersion:\nversion=#{@version}, download=#{@download_path}, id=#{@id}, ksp_version=#{@ksp_version}, changelog=\"#{@changelog}\"\n"
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ module KerbalStuff
2
+ class User
3
+
4
+ attr_reader :json
5
+
6
+ def initialize json
7
+ @json = json
8
+
9
+ @ircNick = @json['ircNick']
10
+ @mods = []
11
+ @twitterUsername = @json['twitterUsername']
12
+ @username = @json['username']
13
+ @redditUsername = @json['redditUsername']
14
+ @forumUsername = @json['forumUsername']
15
+ @description = @json['description']
16
+
17
+ if @json['mods'].length > 0
18
+ @json['mods'].each do |mod|
19
+ @mods.push(Mod.new(mod))
20
+ end
21
+ end
22
+ end
23
+
24
+ def to_s
25
+ "User:\nircNick=#{@ircNick}\nmods=#{@mods}\ntwitterUsername=#{@twitterUsername}\nusername=#{@username}\nredditUsername=#{@redditUsername}\nforumUsername=#{@forumUsername}\ndescription=\"#{@description}\"\n"
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module KerbalStuff
2
+ VERSION = "0.1.6"
3
+ 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.5
4
+ version: 0.1.6
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-25 00:00:00.000000000 Z
12
+ date: 2014-09-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple API wrapper for KerbalStuff
15
15
  email: rockytvbr@gmail.com
@@ -18,8 +18,15 @@ extensions: []
18
18
  extra_rdoc_files:
19
19
  - README.md
20
20
  files:
21
- - lib/KerbalStuff.rb
21
+ - .gitattributes
22
+ - .gitignore
23
+ - KerbalStuff.gemspec
24
+ - LICENSE.txt
22
25
  - README.md
26
+ - lib/KerbalStuff.rb
27
+ - lib/kerbalstuff/mod.rb
28
+ - lib/kerbalstuff/user.rb
29
+ - lib/kerbalstuff/version.rb
23
30
  homepage: https://github.com/RockyTV/KerbalStuffGem
24
31
  licenses:
25
32
  - MIT