Skip to content

Commit

Permalink
wrapped stream
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.addictedtonew.com/public/gems/googlereader@133 fe7eae16-9a24-0410-a59d-9e59979e88be
  • Loading branch information
jnunemaker committed Nov 25, 2007
1 parent 6aab1ab commit 9c7a659
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 94 deletions.
3 changes: 3 additions & 0 deletions History.txt
@@ -1,2 +1,5 @@
* 0.0.2
- added wrapper for google reader preferences (Preference)
- added Base#get_token for retrieving tokens from google
* 0.0.1
- labels and counts are working
4 changes: 3 additions & 1 deletion examples/preferences.rb
Expand Up @@ -9,4 +9,6 @@
pp Google::Reader::Preference.available
pp Google::Reader::Preference[:design]
pp Google::Reader::Preference[:mobile_use_transcoder]
pp Google::Reader::Preference[:mobile_num_entries]
pp Google::Reader::Preference[:mobile_num_entries]

pp Google::Reader::Preference.stream
1 change: 1 addition & 0 deletions lib/google/reader.rb
Expand Up @@ -29,6 +29,7 @@ module Reader
LABEL_URL = READER_URL + '/atom/user/-/label/%s'
UNREAD_COUNT_URL = READER_URL + '/api/0/unread-count?all=true&output=json'
PREFERENCE_URL = READER_URL + '/api/0/preference/list?output=json'
PREFERENCE_STREAM_URL = READER_URL + '/api/0/preference/stream/list?output=json'
PACKAGE = "user/-/state/com.google"

module State
Expand Down
119 changes: 27 additions & 92 deletions lib/google/reader/preference.rb
Expand Up @@ -4,112 +4,47 @@ class Preference < Base
@@greader_preferences = {}

class << self
def load_all
parse_json(get(PREFERENCE_URL))['prefs'].each do |p|
@@greader_preferences[p['id']] = p['value']
end
end

# Returns a sorted list of all the available preference keys
#
# Usage:
# Google::Reader::Preference.available
def available
ensure_preferences_loaded
@@greader_preferences.keys.sort
end

# Gives access to an individual preference. Replace any dash
# in preference key with an underscore. (ie: mobile-num-entries
# is accessed using mobile_num_entries)
#
# Usage:
# Google::Reader::Preference[:design]
# Google::Reader::Preference[:mobile_use_transcoder]
def [](pref)
ensure_preferences_loaded
@@greader_preferences[pref.to_s.gsub('_', '-')]
end

# Returns any preferences set for each feed and label. Not sure
# what this could be helpful for so I'm not sure how to make things
# easily accessible. Right now just returns straight up hash, not
# very useful.
def stream #:nodoc:
parse_json(get(PREFERENCE_STREAM_URL))['streamprefs'].reject { |k,v| v == [] }
end

private
# Gets all the preferences from google
def load_all
parse_json(get(PREFERENCE_URL))['prefs'].each do |p|
@@greader_preferences[p['id']] = p['value']
end
end

def ensure_preferences_loaded
load_all if @@greader_preferences.keys.size == 0
end
end
end
end
end

# {
# "prefs": [
# {
# "id": "start-page",
# "value": "user/00216996281641687092/label/ruby-on-rails"
# },
# {
# "id": "is-legacy-ui-user",
# "value": "true"
# },
# {
# "id": "show-scour-help-go-off",
# "value": "false"
# },
# {
# "id": "animations-disabled",
# "value": "false"
# },
# {
# "id": "show-all-tree-items",
# "value": "false"
# },
# {
# "id": "shuffle-token",
# "value": "228686173662293195"
# },
# {
# "id": "show-oldest-interrupt",
# "value": "true"
# },
# {
# "id": "show-scroll-help",
# "value": "false"
# },
# {
# "id": "show-scour-help-go-on",
# "value": "false"
# },
# {
# "id": "is-card-view",
# "value": "true"
# },
# {
# "id": "scroll-tracking-enabled",
# "value": "true"
# },
# {
# "id": "read-items-visible",
# "value": "false"
# },
# {
# "id": "is-in-scour-mode",
# "value": "false"
# },
# {
# "id": "mobile-use-transcoder",
# "value": "true"
# },
# {
# "id": "queue-sorting",
# "value": "date"
# },
# {
# "id": "design",
# "value": "scroll"
# },
# {
# "id": "show-min-navigation-help",
# "value": "true"
# },
# {
# "id": "display-lang",
# "value": ""
# },
# {
# "id": "mobile-num-entries",
# "value": "9"
# },
# {
# "id": "show-minimized-navigation",
# "value": "false"
# }
# ]
# }
end
2 changes: 1 addition & 1 deletion lib/google/reader/version.rb
Expand Up @@ -3,7 +3,7 @@ module Reader #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 0
TINY = 1
TINY = 2

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down

0 comments on commit 9c7a659

Please sign in to comment.