Class: RemoteCopy

Inherits:
Object
  • Object
show all
Defined in:
lib/rcp.rb

Instance Method Summary collapse

Instance Method Details

#create(channel) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/rcp.rb', line 9

def create(channel)
  uri = URI.parse(base_remote)

  http    = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)

  File.open(File.join(ENV['HOME'], '.rcp'), 'w') { |f| f.write(channel) }
end

#pullObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rcp.rb', line 38

def pull
  channel = File.read(File.join(ENV['HOME'], '.rcp')) || 'global'

  uri           = URI.parse(base_remote + "/pop?channel=#{channel}")

  response      = Net::HTTP.get_response(uri)
  response_json = JSON.parse(response.body)

  @content = response_json["item"]["content"]

  prompt_question if urls.any?

  open_urls if urls.any? && should_i_open?

  copy_to_clipboard

  prompt_message
end

#push(content) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rcp.rb', line 22

def push(content)
  @content = content

  uri = URI.parse(base_remote)

  http    = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)

  channel = File.read(File.join(ENV['HOME'], '.rcp')) || 'global'

  request.set_form_data({ "item[content]" => content,
                          "item[channel]" => channel })

  response = http.request(request)
end

#use(channel) ⇒ Object



18
19
20
# File 'lib/rcp.rb', line 18

def use(channel)
  File.open(File.join(ENV['HOME'], '.rcp'), 'w') { |f| f.write(channel) }
end