Class: Gal

Inherits:
Object
  • Object
show all
Defined in:
lib/gal.rb,
lib/gal/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGal

Returns a new instance of Gal.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gal.rb', line 13

def initialize
  @login = "https://pastebin.com/api/api_login.php"
  @url = "https://pastebin.com/api/api_post.php"
  @raw = "https://pastebin.com/api/api_raw.php"

  @default = {
    api_dev_key: ENV["token"],
    api_user_name: ENV["name"],
    api_user_password: ENV["password"],
    api_user_key: nil,
    api_option: nil,
    api_paste_key: nil,
    api_paste_name: nil,
    api_paste_code: nil,
    api_paste_format: "ruby",
    api_paste_private: "0",
    api_paste_expire_date: "N"
  }

  user_key
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



11
12
13
# File 'lib/gal.rb', line 11

def default
  @default
end

Instance Method Details

#create(options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gal.rb', line 35

def create(options)
  raise "Options must be a hash" unless options.is_a? Hash

  @default[:api_paste_name] = options[:api_paste_name] || "AutoPaste: #{Time.now.strftime("%d/%m/%Y %H:%M:%S")}"
  @default[:api_option] = "paste"
  @default[:api_paste_code] = options[:api_paste_code]

  rsp = RestClient.post @url, @default

  rsp.body
end

#delete(pkey) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/gal.rb', line 47

def delete(pkey)
  raise "Paste key must be a string" unless pkey.is_a? String

  @default[:api_option] = "delete"
  @default[:api_paste_key] = pkey

  rsp = RestClient.post @url, @default

  rsp.body
end

#list_user_entries(num) ⇒ Object Also known as: pastes



66
67
68
69
70
71
72
73
74
75
# File 'lib/gal.rb', line 66

def list_user_entries(num)
  raise "Please provide integer as an argument" unless num.is_a? Integer

  @default[:api_results_limit] = num
  @default[:api_option] = "list"

  rsp = RestClient.post @url, @default

  rsp.body
end

#raw_paste(pkey) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/gal.rb', line 83

def raw_paste(pkey)
  raise "Paste key must be a string" unless pkey.is_a? String

  @default[:api_paste_key] = pkey
  @default[:api_option] = "show_paste"

  rsp = RestClient.post @raw, @default

  rsp.body
end

#show_optionsObject



79
80
81
# File 'lib/gal.rb', line 79

def show_options
  @default
end

#userObject



58
59
60
61
62
63
64
# File 'lib/gal.rb', line 58

def user
  @default[:api_option] = "userdetails"

  rsp = RestClient.post @url, @default

  rsp.body
end