Class: GlipSdk::REST::Posts
- Inherits:
-
Object
- Object
- GlipSdk::REST::Posts
- Defined in:
- lib/glip_sdk/rest/posts.rb
Instance Attribute Summary collapse
-
#groups_cache ⇒ Object
Returns the value of attribute groups_cache.
Instance Method Summary collapse
- #get(opts = {}) ⇒ Object
-
#initialize(rc_sdk) ⇒ Posts
constructor
A new instance of Posts.
- #observe(observer) ⇒ Object
- #post(opts = {}) ⇒ Object
Constructor Details
#initialize(rc_sdk) ⇒ Posts
Returns a new instance of Posts.
8 9 10 |
# File 'lib/glip_sdk/rest/posts.rb', line 8 def initialize(rc_sdk) @api = rc_sdk end |
Instance Attribute Details
#groups_cache ⇒ Object
Returns the value of attribute groups_cache.
6 7 8 |
# File 'lib/glip_sdk/rest/posts.rb', line 6 def groups_cache @groups_cache end |
Instance Method Details
#get(opts = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/glip_sdk/rest/posts.rb', line 37 def get(opts = {}) if opts.key? :postId return @api.http.get "glip/posts/#{opts[:postId]}" end @api.http.get do |req| req.url "glip/posts" req.headers['Content-Type'] = 'application/json' req.body = opts end end |
#observe(observer) ⇒ Object
48 49 50 51 52 |
# File 'lib/glip_sdk/rest/posts.rb', line 48 def observe(observer) @subscription = @api.create_subscription() @subscription.subscribe(['/restapi/v1.0/account/~/extension/~/glip/posts']) @subscription.add_observer observer end |
#post(opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/glip_sdk/rest/posts.rb', line 12 def post(opts = {}) unless opts.key? :text raise ArgumentError, "Text must be provided to post message" end unless opts.key?(:groupId) || opts.key?(:groupName) raise ArgumentError, "Group Id or Group Name must be provided" end group_id = opts[:groupId] if group_id.nil? && @groups_cache && opts.key?(:groupName) group_id = @groups_cache.id_by_name(opts[:groupName]) end params = { groupId: group_id, text: opts[:text] } puts MultiJson.encode params @api.http.post do |req| req.url 'glip/posts' req.headers['Content-Type'] = 'application/json' req.body = { groupId: group_id, text: opts[:text] } end end |