pastie-api 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pastie-api/pastie.rb +14 -1
- metadata +4 -4
data/lib/pastie-api/pastie.rb
CHANGED
@@ -10,13 +10,14 @@ module Pastie
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Creates a new paste
|
13
|
-
def self.create(content, private=true)
|
13
|
+
def self.create(content, private=true, language=nil)
|
14
14
|
params = {
|
15
15
|
"paste[body]" => content.to_s,
|
16
16
|
"paste[authorization]" => "burger",
|
17
17
|
"paste[restricted]" => "1"
|
18
18
|
}
|
19
19
|
params["paste[restricted]"] = "0" unless private
|
20
|
+
params["paste[parser_id]"] = parser_id(language)
|
20
21
|
resp = Net::HTTP.post_form(URI.parse(BASE_URL + "/pastes"), params)
|
21
22
|
if resp.kind_of?(Net::HTTPFound)
|
22
23
|
paste_url = resp.body.scan(/<a href="(.*)">/)[0][0]
|
@@ -25,4 +26,16 @@ module Pastie
|
|
25
26
|
raise "Cannot create paste!"
|
26
27
|
end
|
27
28
|
end
|
29
|
+
|
30
|
+
def self.parser_id(language=nil)
|
31
|
+
return "6" if language.nil? # Default to plain text
|
32
|
+
if @parser.nil?
|
33
|
+
@parser = {}
|
34
|
+
%w{objective_c action_script ruby rails diff plain c css java java_script html erb bash sql php python n_a perl yaml c_sharp}.each_with_index do |lang, ii|
|
35
|
+
@parser[lang] = (ii+1).to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
@parser[language.to_s] || @parser[:plain]
|
39
|
+
end
|
40
|
+
|
28
41
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastie-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dan Sosedoff
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-19 00:00:00 -05:00
|
19
19
|
default_executable: pastie
|
20
20
|
dependencies: []
|
21
21
|
|