Class: Newsfeed::Feed

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

Instance Method Summary collapse

Constructor Details

#initialize(feed_url) ⇒ Feed

Returns a new instance of Feed.

Raises:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/newsfeed/feed.rb', line 5

def initialize(feed_url)
  params = feed_url.split("/")
  base_name = params[-2]
  feed_id = params[-1]
  @feed_key = "#{base_name}:#{feed_id}"
  raise InvalidArgument , "Paramaters too long. max is 512 bytes and got #{String(@feed_key).bytesize}" unless String(@feed_key).bytesize <= 512
  
  @conn = Newsfeed.setup_connection(feed_url) do |faraday|
    faraday.use FeedResponseHandler
  end
end

Instance Method Details

#clone(key) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/newsfeed/feed.rb', line 58

def clone(key)
  key = [key]
  resp = @conn.post do |req|
    req.url "clone"
    req.body = key.to_json
  end

  resp.status
end

#countObject



42
43
44
45
46
47
48
# File 'lib/newsfeed/feed.rb', line 42

def count
  resp = @conn.get do |req|
    req.url "count"
  end

  resp.body
end

#fetch(start = 0, count = 49) ⇒ Object



17
18
19
20
21
22
# File 'lib/newsfeed/feed.rb', line 17

def fetch(start=0, count=49)
  feed = @conn.get do |req|
    req.url "?start=#{start}&count=#{count}"
  end
  feed.body
end

#merge(keys = []) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/newsfeed/feed.rb', line 68

def merge(keys=[])
  resp = @conn.post do |req|
    req.url "merge"
    req.body = keys.to_json
  end

  resp.status
end

#pull(obj) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/newsfeed/feed.rb', line 33

def pull(obj)
  resp = @conn.delete do |req|
    req.url ""
    req.body = obj.to_json
  end

  resp.status 
end

#push(obj) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/newsfeed/feed.rb', line 24

def push(obj)
  resp = @conn.post do |req|
    req.url ""
    req.body = obj.to_json
  end

  resp.status
end

#resetObject



50
51
52
53
54
55
56
# File 'lib/newsfeed/feed.rb', line 50

def reset
  resp = @conn.get do |req|
    req.url "reset"
  end

  resp.status
end