Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Vivien Didelot <vivien.didelot@gmail.com>
To: William@rubyforge.org, Morgan@rubyforge.org, wmorgan-sup@masanjin.net
Cc: Sup developer discussion <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] put the heliotrope client into the Heliotrope namespace
Date: Fri, 24 Jun 2011 01:49:27 -0400	[thread overview]
Message-ID: <1308894567-7174-2-git-send-email-vivien.didelot@gmail.com> (raw)
In-Reply-To: <1308894567-7174-1-git-send-email-vivien.didelot@gmail.com>

Hi William,

To start working on Turnsole,I think putting heliotrope-client
under the Heliotrope namespace in a good start, to avoid
confusion.

This first patch is for the Heliotrope project. It moves
lib/heliotrope-client.rb to lib/heliotrope/client.rb

Another patch is sent with this email to update the Turnsole
client.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 README                   |    2 +-
 lib/heliotrope-client.rb |  102 ---------------------------------------------
 lib/heliotrope/client.rb |  104 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/heliotrope/index.rb  |    2 +-
 4 files changed, 106 insertions(+), 104 deletions(-)
 delete mode 100644 lib/heliotrope-client.rb
 create mode 100644 lib/heliotrope/client.rb

diff --git a/README b/README
index ff82c1d..639e2c2 100644
--- a/README
+++ b/README
@@ -92,4 +92,4 @@ procmailrc or whatever.
 JSON API SPEC
 -------------
 
-Coming soon! For now, you can reverse engineer lib/heliotrope-client.rb.
+Coming soon! For now, you can reverse engineer lib/heliotrope/client.rb.
diff --git a/lib/heliotrope-client.rb b/lib/heliotrope-client.rb
deleted file mode 100644
index 5b3a4bd..0000000
--- a/lib/heliotrope-client.rb
+++ /dev/null
@@ -1,102 +0,0 @@
-require 'rubygems'
-require 'rest_client'
-require 'json'
-
-class HeliotropeClient
-  class Error < StandardError; end
-
-  MESSAGE_MUTABLE_STATE = Set.new %w(starred unread deleted)
-  MESSAGE_IMMUTABLE_STATE = Set.new %w(attachment signed encrypted draft sent)
-  MESSAGE_STATE = MESSAGE_MUTABLE_STATE + MESSAGE_IMMUTABLE_STATE
-
-  attr_reader :url
-  def initialize url
-    @url = url
-    @resource = RestClient::Resource.new url
-  end
-
-  def search query, num=20, start=0
-    v = get_json "search", :q => query, :start => start, :num => num
-    v["results"]
-  end
-
-  def count query
-    get_json("count", :q => query)["count"]
-  end
-
-  def thread id; get_json("thread/#{id}")["messageinfos"] end
-  def threadinfo id; get_json("thread/#{id}/info") end
-
-  def message id, preferred_mime_type="text/plain"
-    get_json "message/#{id}", :mime_type_pref => preferred_mime_type
-  end
-
-  def send_message message, opts={}
-    post_json "message/send", :message => message, :labels => (opts[:labels] || []).to_json
-  end
-
-  def message_part message_id, part_id
-    ## not a json blob, but a binary region
-    @resource["message/#{message_id}/part/#{part_id}"].get
-  end
-
-  def raw_message message_id
-    ## not a json blob, but a binary region
-    @resource["message/#{message_id}/raw"].get
-  end
-
-  def labels; get_json("labels")["labels"] end
-  def info; get_json("info") end
-  def size; get_json("size")["size"] end
-
-  def prune_labels!; post_json("labels/prune")["labels"] end
-
-  def set_labels! thread_id, labels
-    post_json "thread/#{thread_id}/labels", :labels => labels.to_json
-  end
-
-  def set_state! message_id, state
-    post_json "message/#{message_id}/state", :state => state.to_json
-  end
-
-  def set_thread_state! thread_id, state
-    post_json "thread/#{thread_id}/state", :state => state.to_json
-  end
-
-private
-
-  def get_json path, params={}
-    handle_errors do
-      response = @resource[path + ".json"].get :params => params
-      response.force_encoding Encoding::UTF_8 if in_ruby19_hell?
-      JSON.parse response
-    end
-  end
-
-  def post_json path, params={ :please => "1" } # you need to have at least one param for RestClient to work... lame
-    handle_errors do
-      response = @resource[path + ".json"].post params
-      response.force_encoding Encoding::UTF_8 if in_ruby19_hell?
-      JSON.parse response
-    end
-  end
-
-  def handle_errors
-    begin
-      v = yield
-      raise Error, "invalid response: #{v.inspect[0..200]}" unless v.is_a?(Hash)
-      case v["response"]
-        when "ok"; v
-        when "error"; raise Error, v["message"]
-        else raise Error, "invalid response: #{v.inspect[0..200]}"
-      end
-    rescue SystemCallError, RestClient::Exception, JSON::ParserError => e
-      raise Error, "#{e.message} (#{e.class})"
-    end
-  end
-
-  def in_ruby19_hell?
-    @in_ruby19_hell = "".respond_to?(:encoding) if @in_ruby19_hell.nil?
-    @in_ruby19_hell
-  end
-end
diff --git a/lib/heliotrope/client.rb b/lib/heliotrope/client.rb
new file mode 100644
index 0000000..386efc9
--- /dev/null
+++ b/lib/heliotrope/client.rb
@@ -0,0 +1,104 @@
+require 'rubygems'
+require 'rest_client'
+require 'json'
+
+module Heliotrope
+class Client
+  class Error < StandardError; end
+
+  MESSAGE_MUTABLE_STATE = Set.new %w(starred unread deleted)
+  MESSAGE_IMMUTABLE_STATE = Set.new %w(attachment signed encrypted draft sent)
+  MESSAGE_STATE = MESSAGE_MUTABLE_STATE + MESSAGE_IMMUTABLE_STATE
+
+  attr_reader :url
+  def initialize url
+    @url = url
+    @resource = RestClient::Resource.new url
+  end
+
+  def search query, num=20, start=0
+    v = get_json "search", :q => query, :start => start, :num => num
+    v["results"]
+  end
+
+  def count query
+    get_json("count", :q => query)["count"]
+  end
+
+  def thread id; get_json("thread/#{id}")["messageinfos"] end
+  def threadinfo id; get_json("thread/#{id}/info") end
+
+  def message id, preferred_mime_type="text/plain"
+    get_json "message/#{id}", :mime_type_pref => preferred_mime_type
+  end
+
+  def send_message message, opts={}
+    post_json "message/send", :message => message, :labels => (opts[:labels] || []).to_json
+  end
+
+  def message_part message_id, part_id
+    ## not a json blob, but a binary region
+    @resource["message/#{message_id}/part/#{part_id}"].get
+  end
+
+  def raw_message message_id
+    ## not a json blob, but a binary region
+    @resource["message/#{message_id}/raw"].get
+  end
+
+  def labels; get_json("labels")["labels"] end
+  def info; get_json("info") end
+  def size; get_json("size")["size"] end
+
+  def prune_labels!; post_json("labels/prune")["labels"] end
+
+  def set_labels! thread_id, labels
+    post_json "thread/#{thread_id}/labels", :labels => labels.to_json
+  end
+
+  def set_state! message_id, state
+    post_json "message/#{message_id}/state", :state => state.to_json
+  end
+
+  def set_thread_state! thread_id, state
+    post_json "thread/#{thread_id}/state", :state => state.to_json
+  end
+
+private
+
+  def get_json path, params={}
+    handle_errors do
+      response = @resource[path + ".json"].get :params => params
+      response.force_encoding Encoding::UTF_8 if in_ruby19_hell?
+      JSON.parse response
+    end
+  end
+
+  def post_json path, params={ :please => "1" } # you need to have at least one param for RestClient to work... lame
+    handle_errors do
+      response = @resource[path + ".json"].post params
+      response.force_encoding Encoding::UTF_8 if in_ruby19_hell?
+      JSON.parse response
+    end
+  end
+
+  def handle_errors
+    begin
+      v = yield
+      raise Error, "invalid response: #{v.inspect[0..200]}" unless v.is_a?(Hash)
+      case v["response"]
+        when "ok"; v
+        when "error"; raise Error, v["message"]
+        else raise Error, "invalid response: #{v.inspect[0..200]}"
+      end
+    rescue SystemCallError, RestClient::Exception, JSON::ParserError => e
+      raise Error, "#{e.message} (#{e.class})"
+    end
+  end
+
+  def in_ruby19_hell?
+    @in_ruby19_hell = "".respond_to?(:encoding) if @in_ruby19_hell.nil?
+    @in_ruby19_hell
+  end
+end
+end
diff --git a/lib/heliotrope/index.rb b/lib/heliotrope/index.rb
index 48ea09e..197ba91 100644
--- a/lib/heliotrope/index.rb
+++ b/lib/heliotrope/index.rb
@@ -33,7 +33,7 @@ class Index
   MESSAGE_IMMUTABLE_STATE = Set.new %w(attachment signed encrypted draft sent)
   MESSAGE_STATE = MESSAGE_MUTABLE_STATE + MESSAGE_IMMUTABLE_STATE
   ## if you change any of those state things, be sure to update
-  ## heliotrope-client as well.
+  ## heliotrope/client as well.
 
   SNIPPET_MAX_SIZE = 100 # chars
 
-- 
1.7.5.4

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


      reply	other threads:[~2011-06-24  6:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-24  5:49 [sup-devel] [PATCH] update Heliotrope client requirement Vivien Didelot
2011-06-24  5:49 ` Vivien Didelot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1308894567-7174-2-git-send-email-vivien.didelot@gmail.com \
    --to=vivien.didelot@gmail.com \
    --cc=Morgan@rubyforge.org \
    --cc=William@rubyforge.org \
    --cc=sup-devel@rubyforge.org \
    --cc=wmorgan-sup@masanjin.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox