futurest 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/futurest/chapter.rb +36 -0
- data/lib/futurest/paragraph.rb +34 -0
- data/lib/futurest/text.rb +19 -0
- metadata +8 -4
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            module TheFuturest
         | 
| 2 | 
            +
              class Chapter
         | 
| 3 | 
            +
                attr_accessor :id, :title, :number, :errors
         | 
| 4 | 
            +
                
         | 
| 5 | 
            +
                def initialize(attrs)
         | 
| 6 | 
            +
                  @id = attrs["id"]
         | 
| 7 | 
            +
                  @title = attrs["title"]
         | 
| 8 | 
            +
                  @number = attrs["number"]
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                def self.find(id, query = {})
         | 
| 12 | 
            +
                  response = Text.get("/chapter/#{id}", :query => query)
         | 
| 13 | 
            +
                  self.new response.parsed_response
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
                
         | 
| 16 | 
            +
                def self.parse(response)
         | 
| 17 | 
            +
                  chapter = response.parsed_response
         | 
| 18 | 
            +
                  if chapter.is_a? Array
         | 
| 19 | 
            +
                    chapter.map {|c| Chapter.new c }
         | 
| 20 | 
            +
                  else
         | 
| 21 | 
            +
                    Chapter.new chapter
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
                
         | 
| 25 | 
            +
                def paragraphs(query = {})
         | 
| 26 | 
            +
                  Paragraph.parse Text.get("/chapter/#{@id}/paragraphs", :query => query)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
                
         | 
| 29 | 
            +
                def save
         | 
| 30 | 
            +
                  response = Text.post("/chapter/#{@id}", :query => { :title => @title, :number => @number }).parsed_response
         | 
| 31 | 
            +
                  @errors = response["errors"] and return false if response["errors"].any?
         | 
| 32 | 
            +
                  true
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
                
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module TheFuturest  
         | 
| 2 | 
            +
              class Paragraph
         | 
| 3 | 
            +
                attr_accessor :id, :number, :text, :styled_text, :chapter_id, :errors
         | 
| 4 | 
            +
                
         | 
| 5 | 
            +
                def initialize(attrs)
         | 
| 6 | 
            +
                  @id = attrs["id"]
         | 
| 7 | 
            +
                  @number = attrs["number"]
         | 
| 8 | 
            +
                  @text = attrs["text"]
         | 
| 9 | 
            +
                  @styled_text = attrs["styled_text"]
         | 
| 10 | 
            +
                  @chapter_id = attrs["chapter_id"]
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                def self.parse(response)
         | 
| 14 | 
            +
                  paragraph = response.parsed_response
         | 
| 15 | 
            +
                  if paragraph.is_a? Array
         | 
| 16 | 
            +
                    paragraph.map {|p| Paragraph.new p }
         | 
| 17 | 
            +
                  else
         | 
| 18 | 
            +
                    Paragraph.new paragraph
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
                def chapter
         | 
| 23 | 
            +
                  Chapter.parse Text.get("/chapter/#{@chapter_id}")
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
                
         | 
| 26 | 
            +
                def save
         | 
| 27 | 
            +
                  response = Text.post("/chapter/#{@chapter_id}/paragraph/#{@id}", :query => { :text => @text, :number => @number }).parsed_response
         | 
| 28 | 
            +
                  @errors = response["errors"] and return false if response["errors"].any?
         | 
| 29 | 
            +
                  @styled_text = response["paragraph"]["styled_text"]
         | 
| 30 | 
            +
                  return true
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
                
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module TheFuturest
         | 
| 2 | 
            +
              class Text
         | 
| 3 | 
            +
                include HTTParty
         | 
| 4 | 
            +
                default_timeout 10
         | 
| 5 | 
            +
                base_uri 'http://www.thefuturest.info/api'
         | 
| 6 | 
            +
                
         | 
| 7 | 
            +
                def self.search(query = {})
         | 
| 8 | 
            +
                  Paragraph.parse get('/search', :query => query)
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                def self.chapters(query = {})
         | 
| 12 | 
            +
                  Chapter.parse get("/chapters", :query => query)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
                
         | 
| 15 | 
            +
                def self.paragraphs(query = {})
         | 
| 16 | 
            +
                  search query.merge({:regexp => "."})
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: futurest
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -13,7 +13,7 @@ date: 2012-04-04 00:00:00.000000000 Z | |
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: httparty
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &2152499200 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ~>
         | 
| @@ -21,16 +21,20 @@ dependencies: | |
| 21 21 | 
             
                    version: '0.8'
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *2152499200
         | 
| 25 25 | 
             
            description: Wrapper for thefuturest.info's API
         | 
| 26 26 | 
             
            email: j@ckjennin.gs
         | 
| 27 27 | 
             
            executables: []
         | 
| 28 28 | 
             
            extensions: []
         | 
| 29 29 | 
             
            extra_rdoc_files: []
         | 
| 30 30 | 
             
            files:
         | 
| 31 | 
            +
            - lib/futurest/chapter.rb
         | 
| 32 | 
            +
            - lib/futurest/paragraph.rb
         | 
| 33 | 
            +
            - lib/futurest/text.rb
         | 
| 31 34 | 
             
            - lib/futurest.rb
         | 
| 32 35 | 
             
            homepage: http://rubygems.org/gems/futurest
         | 
| 33 | 
            -
            licenses: | 
| 36 | 
            +
            licenses:
         | 
| 37 | 
            +
            - MIT
         | 
| 34 38 | 
             
            post_install_message: 
         | 
| 35 39 | 
             
            rdoc_options: []
         | 
| 36 40 | 
             
            require_paths:
         |