KerbalStuff 0.2.0 → 0.2.1

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,9 @@
1
+ 0.2.1 (November 20, 2014)
2
+ * Added support for **POST** methods (Login, CreateMod, UpdateMod)
3
+ * All methods now return an array containing the info you need. Example: `["name=test", "id=1337"]`
4
+
5
+
6
+
7
+ 0.2.0 (October 25, 2014)
8
+ * Added support for KerbalStuff **browse** methods
9
+ * Added links to Mod.background and ModVersion.download_path
@@ -0,0 +1,17 @@
1
+ # Contributing
2
+
3
+ If you want to help, here's what you need to do:
4
+
5
+ * Fork the repository
6
+ * Change/Add what you want
7
+ * Submit a pull request
8
+
9
+ I'll personally review the request you've made and, if it is good enough, I'll merge it with the master branch.
10
+
11
+
12
+ ### Warning
13
+
14
+ Please don't add more dependencies than what this gem already has. If you are going to add a dependency, please create an issue, with the title as:
15
+ `[DEPENDENCY] rubygems`
16
+
17
+ And then you'll state why you want to add a dependency.
@@ -5,7 +5,7 @@ require "kerbalstuff/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'KerbalStuff'
7
7
  s.version = KerbalStuff::VERSION
8
- s.summary = "KerbalStuff"
8
+ s.summary = "KerbalStuff's Ruby API Wrapper"
9
9
  s.description = "A simple API wrapper for KerbalStuff"
10
10
  s.authors = ["Alexandre Oliveira"]
11
11
  s.email = 'rockytvbr@gmail.com'
data/README.md CHANGED
@@ -59,5 +59,4 @@ licensed under MIT License Copyright (c) 2014 Alexandre Oliveira. See LICENSE fo
59
59
 
60
60
  ## Contributing
61
61
 
62
- If you want to contribute, feel free to do so!
63
- Just fork the repo, make your changes, and then submit the pull-request.
62
+ See [CONTRIBUTING.MD](http://github.com/RockyTV/KerbalStuffGem/CONTRIBUTING.MD)
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'net/http/post/multipart'
2
3
  require 'json'
3
4
  require 'uri'
4
5
 
@@ -8,6 +9,7 @@ module KerbalStuff
8
9
  autoload :Mod, 'kerbalstuff/mod'
9
10
  autoload :ModVerison, 'kerbalstuff/mod'
10
11
  autoload :User, 'kerbalstuff/user'
12
+ autoload :Auth, 'kerbalstuff/auth'
11
13
 
12
14
  def self.get_https_response(url)
13
15
  @url = URI.parse(URI.escape(url))
@@ -0,0 +1,136 @@
1
+ module KerbalStuff
2
+
3
+ class NotLoggedInException < Exception
4
+ end
5
+
6
+ class LoginException < Exception
7
+ end
8
+
9
+ class ErrorException < Exception
10
+ end
11
+
12
+ class Auth
13
+
14
+ attr_accessor :cookie
15
+
16
+ # Logs into Kerbal Stuff.
17
+ #
18
+ # @param username [String]
19
+ # @param password [String]
20
+ # @return [Array] An array with the status of the login.
21
+ def self.login(params = {})
22
+ @username = params['username']
23
+ @password = params['password']
24
+
25
+ url = URI.parse("https://kerbalstuff.com/api/login")
26
+
27
+ http = Net::HTTP.new(url.host, url.port)
28
+ http.use_ssl = true
29
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
30
+
31
+ req = Net::HTTP::Post::Multipart.new url.path, "username" => @username, "password" => @password
32
+
33
+ res = http.start do |http2|
34
+ http2.request(req)
35
+ end
36
+
37
+ resp = JSON.parse(res.body)
38
+ if resp['error'] == false
39
+ @cookie = res.header['set-cookie']
40
+ return ["error=false", "info=Logged in successfully."]
41
+ else
42
+ return ["error=true", "info=#{resp['reason']}"]
43
+ end
44
+ end
45
+
46
+ # Creates a new mod. Requires authentication.
47
+ #
48
+ # @param name [String] Your new mod's name
49
+ # @param desc [String] Short description of your mod
50
+ # @param version [String] The latest friendly version of your mod
51
+ # @param ksp_ver [String] The KSP version this is compatible with
52
+ # @param license [String] Your mod's license
53
+ # @param zipball [File] The actual mod's zip file
54
+ # @return [Array] An array containing the published mod info.
55
+ def self.create_mod(params = {})
56
+ @name = params['name']
57
+ @desc = params['desc']
58
+ @version = params['version']
59
+ @ksp_ver = params['ksp_ver']
60
+ @license = params['license']
61
+ @zipball = params['zipball']
62
+
63
+ url = URI.parse("https://kerbalstuff.com/api/mod/create")
64
+
65
+ http = Net::HTTP.new(url.host, url.port)
66
+ http.use_ssl = true
67
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
68
+
69
+ File.open(@zipball, "r") do |file|
70
+
71
+ req = Net::HTTP::Post::Multipart.new url.path, "name" => @name, "short-description" => @desc, "version" => @version, "ksp-version" => @ksp_ver, "license" => @license,
72
+ "zipball" => UploadIO.new(file, "application/zip", File.basename(file))
73
+ req.add_field("Cookie", @cookie)
74
+
75
+ res = http.start do |http2|
76
+ http2.request(req)
77
+ end
78
+
79
+ resp = JSON.parse(res.body)
80
+
81
+ if resp['error'] == true
82
+ return ["error=true", "msg=#{resp['reason']}"]
83
+ else
84
+ return ["id=#{resp['id']}", "name=#{resp['name']}", "url=http:""/""/""kerbalstuff.com#{resp['url']}"]
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ # Publishes an update to an existing mod. Requires authentication. All parameters are required. Parameters are passed by via Hash.
91
+ #
92
+ # @param modid [Fixnum] The ID of the mod you want to update
93
+ # @param version [String] The friendly version number about to be created
94
+ # @param changelog [String] Markdown changelog
95
+ # @param ksp_ver [String] The version of KSP this is compatible with
96
+ # @param notify_followers [String] If "yes", email followers about this update
97
+ # @param zipball [File] The actual mod's zip file
98
+ # @return [Array] A string containing the updated version info.
99
+ def self.update_mod(params = {})
100
+ raise ArgumentError, "Params cannot be empty" if params.empty?
101
+ raise ArgumentError, "Missing one or more parameters" unless (params.has_key?("modid") && params.has_key?("version") && params.has_key?("changelog") && params.has_key?("ksp_ver") && params.has_key?("notify_followers") && params.has_key?("zipball"))
102
+
103
+ modid = params['modid']
104
+ @version = params['version']
105
+ @changelog = params['changelog']
106
+ @ksp_ver = params['ksp_ver']
107
+ @notify_followers = params['notify_followers']
108
+ @zipball = params['zipball']
109
+
110
+ url = URI.parse("https://kerbalstuff.com/api/mod/#{modid}/update")
111
+
112
+ http = Net::HTTP.new(url.host, url.port)
113
+ http.use_ssl = true
114
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
115
+
116
+ File.open(@zipball, "r") do |file|
117
+
118
+ req = Net::HTTP::Post::Multipart.new url.path, "version" => @version, "changelog" => @changelog, "ksp-version" => @ksp_ver, "notify-followers" => @notify_followers,
119
+ "zipball" => UploadIO.new(file, "application/zip", File.basename(file))
120
+ req.add_field("Cookie", @cookie)
121
+
122
+ res = http.start do |http2|
123
+ http2.request(req)
124
+ end
125
+
126
+ resp = JSON.parse(res.body)
127
+
128
+ if resp['error'] == true
129
+ return ["error=true", "msg=#{resp['reason']}"]
130
+ else
131
+ return ["id=#{resp['id']}", "url=http:""/""/#{resp['url']}"]
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -33,7 +33,7 @@ module KerbalStuff
33
33
  end
34
34
 
35
35
  def to_s
36
- "Mod:\nname=#{@name}\nbackground=https:""/""/""cdn.mediacru.sh#{@background}\nlicense=#{@license}\nwebsite=#{@website}\ndonations=#{@donations}\nsource_code=#{@source_code}\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"
36
+ return ["name=#{@name}", "background=https:""/""/""cdn.mediacru.sh#{@background}", "license=#{@license}", "website=#{@website}", "donations=#{@donations}", "source_code=#{@source_code}", "author=#{@author}", "downloads=#{@downloads}", "id=#{@id}", "short_description=\"#{@short_description}\"", "versions=#{@versions}", "description_html=\"#{@description_html}\"", "followers=#{@followers}", "default_version_id=#{@default_version_id}", "description=\"#{@description}\""]
37
37
  end
38
38
  end
39
39
 
@@ -52,7 +52,7 @@ module KerbalStuff
52
52
  end
53
53
 
54
54
  def to_s
55
- "ModVersion:\nversion=#{@version}, download=https:""/""/""kerbalstuff.com#{@download_path}, id=#{@id}, ksp_version=#{@ksp_version}, changelog=\"#{@changelog}\"\n"
55
+ ["version=#{@version}", "download=https:""/""/""kerbalstuff.com#{@download_path}", "id=#{@id}", "ksp_version=#{@ksp_version}", "changelog=\"#{@changelog}\""]
56
56
  end
57
57
  end
58
58
  end
@@ -22,7 +22,7 @@ module KerbalStuff
22
22
  end
23
23
 
24
24
  def to_s
25
- "User:\nircNick=#{@ircNick}\nmods=#{@mods}\ntwitterUsername=#{@twitterUsername}\nusername=#{@username}\nredditUsername=#{@redditUsername}\nforumUsername=#{@forumUsername}\ndescription=\"#{@description}\"\n"
25
+ return ["ircNick=#{@ircNick}", "mods=#{@mods}", "twitterUsername=#{@twitterUsername}", "username=#{@username}", "redditUsername=#{@redditUsername}", "forumUsername=#{@forumUsername}", "description=\"#{@description}\""]
26
26
  end
27
27
 
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module KerbalStuff
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
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.2.0
4
+ version: 0.2.1
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-10-25 00:00:00.000000000 Z
12
+ date: 2014-11-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple API wrapper for KerbalStuff
15
15
  email: rockytvbr@gmail.com
@@ -20,10 +20,13 @@ extra_rdoc_files:
20
20
  files:
21
21
  - .gitattributes
22
22
  - .gitignore
23
+ - CHANGELOG.md
24
+ - CONTRIBUTING.md
23
25
  - KerbalStuff.gemspec
24
26
  - LICENSE.txt
25
27
  - README.md
26
28
  - lib/KerbalStuff.rb
29
+ - lib/kerbalstuff/auth.rb
27
30
  - lib/kerbalstuff/mod.rb
28
31
  - lib/kerbalstuff/user.rb
29
32
  - lib/kerbalstuff/version.rb
@@ -51,5 +54,5 @@ rubyforge_project:
51
54
  rubygems_version: 1.8.28
52
55
  signing_key:
53
56
  specification_version: 3
54
- summary: KerbalStuff
57
+ summary: KerbalStuff's Ruby API Wrapper
55
58
  test_files: []